feat: format
This commit is contained in:
@@ -11,8 +11,8 @@ func isSupportSecureEnclave() -> Bool {
|
||||
}
|
||||
|
||||
func generateSecureEnclaveP256KeyPair(sign: Bool, requireBio: Bool) -> String {
|
||||
var error: Unmanaged<CFError>? = nil;
|
||||
let accessControlCreateFlags: SecAccessControlCreateFlags;
|
||||
var error: Unmanaged<CFError>? = nil
|
||||
let accessControlCreateFlags: SecAccessControlCreateFlags
|
||||
if (requireBio) {
|
||||
accessControlCreateFlags = [.privateKeyUsage, .biometryCurrentSet]
|
||||
} else {
|
||||
@@ -30,7 +30,7 @@ func generateSecureEnclaveP256KeyPair(sign: Bool, requireBio: Bool) -> String {
|
||||
if (sign) {
|
||||
let privateKeyReference = try SecureEnclave.P256.Signing.PrivateKey.init(
|
||||
accessControl: accessCtrl
|
||||
);
|
||||
)
|
||||
let publicKeyBase64 = privateKeyReference.publicKey.x963Representation.base64EncodedString()
|
||||
let publicKeyPem = privateKeyReference.publicKey.derRepresentation.base64EncodedString()
|
||||
let dataRepresentationBase64 = privateKeyReference.dataRepresentation.base64EncodedString()
|
||||
@@ -38,7 +38,7 @@ func generateSecureEnclaveP256KeyPair(sign: Bool, requireBio: Bool) -> String {
|
||||
} else {
|
||||
let privateKeyReference = try SecureEnclave.P256.KeyAgreement.PrivateKey.init(
|
||||
accessControl: accessCtrl
|
||||
);
|
||||
)
|
||||
let publicKeyBase64 = privateKeyReference.publicKey.x963Representation.base64EncodedString()
|
||||
let publicKeyPem = privateKeyReference.publicKey.derRepresentation.base64EncodedString()
|
||||
let dataRepresentationBase64 = privateKeyReference.dataRepresentation.base64EncodedString()
|
||||
@@ -50,7 +50,7 @@ func generateSecureEnclaveP256KeyPair(sign: Bool, requireBio: Bool) -> String {
|
||||
}
|
||||
|
||||
func recoverSecureEnclaveP256PublicKeyEcsign(privateKeyDataRepresentation: String) -> String {
|
||||
return recoverSecureEnclaveP256PublicKey(privateKeyDataRepresentation: privateKeyDataRepresentation, sign: true);
|
||||
return recoverSecureEnclaveP256PublicKey(privateKeyDataRepresentation: privateKeyDataRepresentation, sign: true)
|
||||
}
|
||||
|
||||
func recoverSecureEnclaveP256PublicKey(privateKeyDataRepresentation: String, sign: Bool) -> String {
|
||||
@@ -60,7 +60,7 @@ func recoverSecureEnclaveP256PublicKey(privateKeyDataRepresentation: String, sig
|
||||
return "err:private key base64 decode failed"
|
||||
}
|
||||
do {
|
||||
let context = LAContext();
|
||||
let context = LAContext()
|
||||
if (sign) {
|
||||
let privateKeyReference = try SecureEnclave.P256.Signing.PrivateKey(
|
||||
dataRepresentation: privateKeyDataRepresentation,
|
||||
@@ -97,7 +97,7 @@ func computeSecureEnclaveP256Ecsign(privateKeyDataRepresentation: String, conten
|
||||
return "err:content base64 decode failed"
|
||||
}
|
||||
do {
|
||||
let context = LAContext();
|
||||
let context = LAContext()
|
||||
let p = try SecureEnclave.P256.Signing.PrivateKey(
|
||||
dataRepresentation: privateKeyDataRepresentation,
|
||||
authenticationContext: context
|
||||
@@ -124,7 +124,7 @@ func computeSecureEnclaveP256Ecdh(privateKeyDataRepresentation: String, ephemera
|
||||
return "err:ephemeral public key base64 decode failed"
|
||||
}
|
||||
do {
|
||||
let context = LAContext();
|
||||
let context = LAContext()
|
||||
let p = try SecureEnclave.P256.KeyAgreement.PrivateKey(
|
||||
dataRepresentation: privateKeyDataRepresentation,
|
||||
authenticationContext: context
|
||||
@@ -143,7 +143,7 @@ func computeSecureEnclaveP256Ecdh(privateKeyDataRepresentation: String, ephemera
|
||||
|
||||
func readArgumentAsBool(index: Int, defaultValue: Bool) -> Bool {
|
||||
if CommandLine.arguments.count >= index + 1 {
|
||||
let val = CommandLine.arguments[index];
|
||||
let val = CommandLine.arguments[index]
|
||||
if (val == "true" || val == "yes" || val == "on" || val == "1") {
|
||||
return true
|
||||
}
|
||||
@@ -153,7 +153,7 @@ func readArgumentAsBool(index: Int, defaultValue: Bool) -> Bool {
|
||||
}
|
||||
|
||||
func exitWith(_ response: String) {
|
||||
print(response);
|
||||
print(response)
|
||||
if (response.hasPrefix("ok:")) {
|
||||
exit(0)
|
||||
} else {
|
||||
@@ -166,7 +166,7 @@ if (CommandLine.arguments.count == 1) {
|
||||
exitWith("err:require one argument")
|
||||
}
|
||||
|
||||
let command = CommandLine.arguments[1];
|
||||
let command = CommandLine.arguments[1]
|
||||
|
||||
if (command == "is_support_secure_enclave") {
|
||||
exitWith("ok:\(isSupportSecureEnclave())")
|
||||
@@ -218,7 +218,7 @@ if (command == "compute_secure_enclave_p256_ecdh") {
|
||||
let response = computeSecureEnclaveP256Ecdh(
|
||||
privateKeyDataRepresentation: CommandLine.arguments[2],
|
||||
ephemeraPublicKey: CommandLine.arguments[3]
|
||||
);
|
||||
)
|
||||
exitWith(response)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user