-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add local fork of the go-touchid library
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/lox/go-touchid | ||
|
||
go 1.16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package touchid | ||
|
||
// Forked from: https://github.com/lox/go-touchid | ||
// Commit 619cc8e578d0ef916aa29c806117c370f9d621cb | ||
// Unknown license. | ||
|
||
/* | ||
#cgo CFLAGS: -x objective-c -fmodules -fblocks | ||
#cgo LDFLAGS: -framework CoreFoundation -framework LocalAuthentication -framework Foundation | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#import <LocalAuthentication/LocalAuthentication.h> | ||
int Authenticate(char const* reason) { | ||
LAContext *myContext = [[LAContext alloc] init]; | ||
NSError *authError = nil; | ||
dispatch_semaphore_t sema = dispatch_semaphore_create(0); | ||
NSString *nsReason = [NSString stringWithUTF8String:reason]; | ||
__block int result = 0; | ||
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { | ||
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics | ||
localizedReason:nsReason | ||
reply:^(BOOL success, NSError *error) { | ||
if (success) { | ||
result = 1; | ||
} else { | ||
result = 2; | ||
} | ||
dispatch_semaphore_signal(sema); | ||
}]; | ||
} | ||
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); | ||
dispatch_release(sema); | ||
return result; | ||
} | ||
*/ | ||
import ( | ||
"C" | ||
) | ||
import ( | ||
"errors" | ||
"unsafe" | ||
) | ||
|
||
func Authenticate(reason string) (bool, error) { | ||
reasonStr := C.CString(reason) | ||
defer C.free(unsafe.Pointer(reasonStr)) | ||
|
||
result := C.Authenticate(reasonStr) | ||
switch result { | ||
case 1: | ||
return true, nil | ||
case 2: | ||
return false, nil | ||
} | ||
|
||
return false, errors.New("Error occurred accessing biometrics") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters