Skip to content

Commit fc2c0d6

Browse files
committed
Minor cleanup
1 parent eddfc46 commit fc2c0d6

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

src/org/dyorgio/jna/platform/mac/Security.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.sun.jna.platform.mac.CoreFoundation;
2222
import com.sun.jna.ptr.IntByReference;
2323
import com.sun.jna.ptr.PointerByReference;
24-
import qz.printer.status.Cups;
2524

2625
/**
2726
* The JNA library interface to access the Security library under MacOS.
@@ -32,43 +31,45 @@ public interface Security extends Library {
3231

3332
Security INSTANCE = Native.load("Security", Security.class);
3433

35-
enum SecBase {
36-
errSecSuccess(0, "No error."),
37-
errSecUnimplemented(-4, "Function or operation not implemented."),
38-
errSecIO(-36, "I/O error (bummers)"),
39-
errSecOpWr(-49, "file already open with with write permission"),
40-
errSecParam(-50, "One or more parameters passed to a function where not valid."),
41-
errSecAllocate(-108, "Failed to allocate memory."),
42-
errSecUserCanceled(-128, "User canceled the operation."),
43-
errSecBadReq(-909, "Bad parameter or invalid state for operation."),
44-
errSecInternalComponent(-2070,"Internal component failure"),
45-
errSecNotAvailable(-25291, "No keychain is available. You may need to restart your computer."),
46-
errSecDuplicateItem(-25299, "The specified item already exists in the keychain."),
47-
errSecItemNotFound(-25300, "The specified item could not be found in the keychain."),
48-
errSecInteractionNotAllowed(-25308, "User interaction is not allowed."),
49-
errSecDecode (-26275, "Unable to decode the provided data."),
50-
errSecAuthFailed(-25293, "The user name or passphrase you entered is not correct."),
51-
UNKNOWN(-99999, "Code not mapped");
34+
enum Status {
35+
SUCCESS("errSecSuccess", 0, "No error."),
36+
UNIMPLEMENTED("errSecUnimplemented", -4, "Function or operation not implemented."),
37+
IO("errSecIO", -36, "I/O error (bummers)"),
38+
OPWR("errSecOpWr", -49, "File already open with write permission"),
39+
PARAM("errSecParam", -50, "One or more parameters passed to a function where not valid."),
40+
ALLOCATE("errSecAllocate", -108, "Failed to allocate memory."),
41+
USER_CANCELED("errSecUserCanceled", -128, "User canceled the operation."),
42+
BAD_REQ("errSecBadReq", -909, "Bad parameter or invalid state for operation."),
43+
INTERNAL_COMPONENT("errSecInternalComponent", -2070,"Internal component failure"),
44+
NOT_AVAILABLE("errSecNotAvailable", -25291, "No keychain is available. You may need to restart your computer."),
45+
DUPLICATE_ITEM("errSecDuplicateItem", -25299, "The specified item already exists in the keychain."),
46+
ITEM_NOT_FOUND("errSecItemNotFound", -25300, "The specified item could not be found in the keychain."),
47+
INTERACTION_NOT_ALLOWED("errSecInteractionNotAllowed", -25308, "User interaction is not allowed."),
48+
DECODE ("errSecDecode", -26275, "Unable to decode the provided data."),
49+
AUTH_FAILED("errSecAuthFailed", -25293, "The user name or passphrase you entered is not correct."),
50+
UNKNOWN("unknown", -99999, "Code not mapped");
5251

5352
int code;
53+
String name;
5454
String message;
55-
SecBase(int code, String message) {
55+
Status(String name, int code, String message) {
56+
this.name = name;
5657
this.code = code;
5758
this.message = message;
5859
}
5960

60-
public static SecBase parse(int code) {
61-
for(SecBase secBase : SecBase.values()) {
62-
if(code == secBase.code) {
63-
return secBase;
61+
public static Status parse(int code) {
62+
for(Status status : Status.values()) {
63+
if(code == status.code) {
64+
return status;
6465
}
6566
}
6667
return UNKNOWN;
6768
}
6869

6970
@Override
7071
public String toString() {
71-
return String.format("(%d) [%s] %s", this.code, this.name(), this.message);
72+
return String.format("(%d) [%s] %s", this.code, name, this.message);
7273
}
7374
}
7475

src/org/dyorgio/jna/platform/mac/Security_Main_Temp.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ public static void main(String ... args) {
1919
CFStringRef kSecClassCertificate = CFStringRef.createCFString("kSecClassCertificate");
2020
CFStringRef cfLabel = CFStringRef.createCFString("My Certificate");
2121
CFDataRef cfValueAsData = getCFDataCert(DER_ENCODED_CERT);
22-
//CFStringRef cfValueAsString = CFStringRef.createCFString(DER_ENCODED_CERT);
2322
CFTypeRef cfValueAsCert = Security.INSTANCE.SecCertificateCreateWithData(null, cfValueAsData);
2423

2524
CFStringRef summary = Security.INSTANCE.SecCertificateCopySubjectSummary(cfValueAsCert);
26-
System.out.println(summary.stringValue());
25+
System.out.println("SecCertificateCopySubjectSummary: " + summary.stringValue());
2726
summary.release();
2827

2928
// Write to dictionary
@@ -33,11 +32,11 @@ public static void main(String ... args) {
3332

3433
// Call SecAddItem
3534
int retVal = Security.INSTANCE.SecItemAdd(dict.getPointer(), null);
36-
Security.SecBase code = Security.SecBase.parse(retVal);
35+
Security.Status code = Security.Status.parse(retVal);
3736

3837
// Show output
3938
switch(code) {
40-
case errSecSuccess:
39+
case SUCCESS:
4140
System.out.println(code);
4241
break;
4342
default:
@@ -51,8 +50,7 @@ public static void main(String ... args) {
5150

5251
kSecClassCertificate.release();
5352
cfLabel.release();
54-
// cfValueAsData.release();
55-
//cfValueAsString.release();
53+
cfValueAsData.release();
5654

5755
dict.release();
5856
alloc.release();

0 commit comments

Comments
 (0)