This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
forked from keys-pub/zkgroup
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauth_credential.go
71 lines (60 loc) · 2.33 KB
/
auth_credential.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package zkgroup
/*
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_x86_64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_aarch64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_armv7
#include "lib/zkgroup.h"
*/
import "C"
import "encoding/binary"
// AuthCredential ...
type AuthCredential []byte
// NewAuthCredential ...
func NewAuthCredential(b []byte) (AuthCredential, error) {
if res := C.FFI_AuthCredential_checkValidContents(cBytes(b), cLen(b)); res != C.FFI_RETURN_OK {
return nil, errFromCode(res)
}
return AuthCredential(b), nil
}
// AuthCredentialResponse ...
type AuthCredentialResponse []byte
// NewAuthCredentialResponse ...
func NewAuthCredentialResponse(b []byte) (AuthCredentialResponse, error) {
if res := C.FFI_AuthCredentialResponse_checkValidContents(cBytes(b), cLen(b)); res != C.FFI_RETURN_OK {
return nil, errFromCode(res)
}
return AuthCredentialResponse(b), nil
}
// AuthCredentialPresentation ...
type AuthCredentialPresentation []byte
// NewAuthCredentialPresentation ...
func NewAuthCredentialPresentation(b []byte) (AuthCredentialPresentation, error) {
if res := C.FFI_AuthCredentialPresentation_checkValidContents(cBytes(b), cLen(b)); res != C.FFI_RETURN_OK {
return nil, errFromCode(res)
}
return AuthCredentialPresentation(b), nil
}
// UUIDCiphertext ...
func (a AuthCredentialPresentation) UUIDCiphertext() ([]byte, error) {
out := make([]byte, C.UUID_CIPHERTEXT_LEN)
if res := C.FFI_AuthCredentialPresentation_getUuidCiphertext(cBytes(a), cLen(a), cBytes(out), cLen(out)); res != C.FFI_RETURN_OK {
return nil, errFromCode(res)
}
return out, nil
}
// ProfileKeyCiphertext ...
func (a AuthCredentialPresentation) ProfileKeyCiphertext() ([]byte, error) {
out := make([]byte, C.PROFILE_KEY_CIPHERTEXT_LEN)
if res := C.FFI_ProfileKeyCredentialPresentation_getProfileKeyCiphertext(cBytes(a), cLen(a), cBytes(out), cLen(out)); res != C.FFI_RETURN_OK {
return nil, errFromCode(res)
}
return out, nil
}
// RedemptionTime ...
func (a AuthCredentialPresentation) RedemptionTime() (uint32, error) {
out := make([]byte, 4)
if res := C.FFI_AuthCredentialPresentation_getRedemptionTime(cBytes(a), cLen(a), cBytes(out), cLen(out)); res != C.FFI_RETURN_OK {
return 0, errFromCode(res)
}
return binary.BigEndian.Uint32(out), nil
}