-
Notifications
You must be signed in to change notification settings - Fork 0
/
signer.go
93 lines (80 loc) · 2.63 KB
/
signer.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package authenticity
import (
"github.com/bloock/bloock-sdk-go/v2/entity/key"
"github.com/bloock/bloock-sdk-go/v2/internal/bridge/proto"
)
// Signer represents a signer with various key types and additional configurations.
type Signer struct {
LocalKey *key.LocalKey
ManagedKey *key.ManagedKey
ManagedCertificate *key.ManagedCertificate
LocalCertificate *key.LocalCertificate
HashAlg *HashAlg
AccessControl *key.AccessControl
}
// NewSignerWithLocalKey creates a Signer instance with a local key and specified hash algorithm.
func NewSignerWithLocalKey(key key.LocalKey, hashAlg *HashAlg) Signer {
return Signer{
LocalKey: &key,
HashAlg: hashAlg,
}
}
// NewSignerWithManagedKey creates a Signer instance with a managed key, specified hash algorithm,
// and access control configuration.
func NewSignerWithManagedKey(key key.ManagedKey, hashAlg *HashAlg, accessControl *key.AccessControl) Signer {
return Signer{
ManagedKey: &key,
HashAlg: hashAlg,
AccessControl: accessControl,
}
}
// NewSignerWithLocalCertificate creates a Signer instance with a local certificate and specified hash algorithm.
func NewSignerWithLocalCertificate(key key.LocalCertificate, hashAlg *HashAlg) Signer {
return Signer{
LocalCertificate: &key,
HashAlg: hashAlg,
}
}
// NewSignerWithManagedCertificate creates a Signer instance with a managed certificate, specified hash algorithm,
// and access control configuration.
func NewSignerWithManagedCertificate(key key.ManagedCertificate, hashAlg *HashAlg, accessControl *key.AccessControl) Signer {
return Signer{
ManagedCertificate: &key,
HashAlg: hashAlg,
AccessControl: accessControl,
}
}
func (s Signer) ToProto() *proto.Signer {
var localKey *proto.LocalKey
if s.LocalKey != nil {
localKey = s.LocalKey.ToProto()
}
var managedKey *proto.ManagedKey
if s.ManagedKey != nil {
managedKey = s.ManagedKey.ToProto()
}
var managedCertificate *proto.ManagedCertificate
if s.ManagedCertificate != nil {
managedCertificate = s.ManagedCertificate.ToProto()
}
var localCertificate *proto.LocalCertificate
if s.LocalCertificate != nil {
localCertificate = s.LocalCertificate.ToProto()
}
var hashAlg *proto.HashAlg
if s.HashAlg != nil {
hashAlg = HashAlgToProto[*s.HashAlg]
}
var accessControl *proto.AccessControl
if s.AccessControl != nil {
accessControl = s.AccessControl.ToProto()
}
return &proto.Signer{
LocalKey: localKey,
ManagedKey: managedKey,
ManagedCertificate: managedCertificate,
LocalCertificate: localCertificate,
HashAlg: hashAlg,
AccessControl: accessControl,
}
}