@@ -34,47 +34,32 @@ type config interface {
3434 PrimitiveFromKey (key key.Key , _ internalapi.Token ) (any , error )
3535}
3636
37- type primitiveFunc func (serializedKey [] byte ) (any , error )
37+ type primitiveConstructor func (key key. Key ) (any , error )
3838
3939// KeyManager implements the [registry.KeyManager] interface.
4040type KeyManager struct {
41- typeURL string
42- config config
43- protoKeyUnmashaller func ([]byte ) (proto.Message , error )
44- keyMaterialType tinkpb.KeyData_KeyMaterialType
45- primitiveFunc primitiveFunc
41+ typeURL string
42+ protoKeyUnmashaller func ([]byte ) (proto.Message , error )
43+ keyMaterialType tinkpb.KeyData_KeyMaterialType
44+ primitiveConstructor primitiveConstructor
4645}
4746
4847var _ registry.KeyManager = (* KeyManager )(nil )
4948
5049// New creates a new [LegacyKeyManager].
5150//
5251// Assumes parameters are not nil.
53- func New (typeURL string , config config , keyMaterialType tinkpb.KeyData_KeyMaterialType , protoKeyUnmashaller func ([]byte ) (proto.Message , error )) * KeyManager {
54- km := & KeyManager {
55- typeURL : typeURL ,
56- config : config ,
57- protoKeyUnmashaller : protoKeyUnmashaller ,
58- keyMaterialType : keyMaterialType ,
59- }
60- km .primitiveFunc = km .defaultPrimitiveFunc
61- return km
62- }
63-
64- // NewWithCustomPrimitive creates a new [LegacyKeyManager] with a custom primitive function.
65- //
66- // Assumes parameters are not nil.
67- func NewWithCustomPrimitive (typeURL string , config config , keyMaterialType tinkpb.KeyData_KeyMaterialType , protoKeyUnmashaller func ([]byte ) (proto.Message , error ), pf primitiveFunc ) * KeyManager {
52+ func New (typeURL string , primitiveConstructor primitiveConstructor , keyMaterialType tinkpb.KeyData_KeyMaterialType , protoKeyUnmashaller func ([]byte ) (proto.Message , error )) * KeyManager {
6853 return & KeyManager {
69- typeURL : typeURL ,
70- config : config ,
71- protoKeyUnmashaller : protoKeyUnmashaller ,
72- keyMaterialType : keyMaterialType ,
73- primitiveFunc : pf ,
54+ typeURL : typeURL ,
55+ protoKeyUnmashaller : protoKeyUnmashaller ,
56+ keyMaterialType : keyMaterialType ,
57+ primitiveConstructor : primitiveConstructor ,
7458 }
7559}
7660
77- func (m * KeyManager ) defaultPrimitiveFunc (serializedKey []byte ) (any , error ) {
61+ // Primitive creates a primitive from the given serialized key.
62+ func (m * KeyManager ) Primitive (serializedKey []byte ) (any , error ) {
7863 keySerialization , err := protoserialization .NewKeySerialization (& tinkpb.KeyData {
7964 TypeUrl : m .typeURL ,
8065 Value : serializedKey ,
@@ -87,12 +72,7 @@ func (m *KeyManager) defaultPrimitiveFunc(serializedKey []byte) (any, error) {
8772 if err != nil {
8873 return nil , err
8974 }
90- return m .config .PrimitiveFromKey (key , internalapi.Token {})
91- }
92-
93- // Primitive creates a primitive from the given serialized key.
94- func (m * KeyManager ) Primitive (serializedKey []byte ) (any , error ) {
95- return m .primitiveFunc (serializedKey )
75+ return m .primitiveConstructor (key )
9676}
9777
9878// NewKey creates a new key from the given serialized key format.
@@ -150,16 +130,9 @@ type PrivateKeyManager struct {
150130var _ registry.PrivateKeyManager = (* PrivateKeyManager )(nil )
151131
152132// NewPrivateKeyManager creates a new [PrivateKeyManager].
153- func NewPrivateKeyManager (typeURL string , config config , keyMaterialType tinkpb.KeyData_KeyMaterialType , protoKeyUnmashaller func ([]byte ) (proto.Message , error )) * PrivateKeyManager {
154- return & PrivateKeyManager {
155- KeyManager : * New (typeURL , config , keyMaterialType , protoKeyUnmashaller ),
156- }
157- }
158-
159- // NewPrivateKeyManagerWithCustomPrimitive creates a new [PrivateKeyManager] with a custom primitive function.
160- func NewPrivateKeyManagerWithCustomPrimitive (typeURL string , config config , keyMaterialType tinkpb.KeyData_KeyMaterialType , protoKeyUnmashaller func ([]byte ) (proto.Message , error ), pf primitiveFunc ) * PrivateKeyManager {
133+ func NewPrivateKeyManager (typeURL string , primitiveConstructor primitiveConstructor , keyMaterialType tinkpb.KeyData_KeyMaterialType , protoKeyUnmashaller func ([]byte ) (proto.Message , error )) * PrivateKeyManager {
161134 return & PrivateKeyManager {
162- KeyManager : * NewWithCustomPrimitive (typeURL , config , keyMaterialType , protoKeyUnmashaller , pf ),
135+ KeyManager : * New (typeURL , primitiveConstructor , keyMaterialType , protoKeyUnmashaller ),
163136 }
164137}
165138
0 commit comments