github.com/trustbloc/kms-go@v1.1.2/mock/crypto/mock_crypto.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package crypto 8 9 import ( 10 cryptoapi "github.com/trustbloc/kms-go/spi/crypto" 11 ) 12 13 // SignFunc mocks Crypto's Sign() function, it's useful for executing custom signing with the help of SignKey. 14 type SignFunc func([]byte, interface{}) ([]byte, error) 15 16 // BBSSignFunc mocks Crypto's BBSSign() function, it's useful for executing custom BBS+ signing with the help of 17 // Signing private Key. 18 type BBSSignFunc func([][]byte, interface{}) ([]byte, error) 19 20 // DeriveProofFunc mocks Crypto's DeriveProofFunc() function, it's useful for executing custom BBS+ signing with the 21 // help of Signing public Key. 22 type DeriveProofFunc func([][]byte, []byte, []byte, []int, interface{}) ([]byte, error) 23 24 // Crypto mock. 25 type Crypto struct { 26 EncryptValue []byte 27 EncryptNonceValue []byte 28 EncryptErr error 29 DecryptValue []byte 30 DecryptErr error 31 SignValue []byte 32 SignKey []byte 33 SignFn SignFunc 34 SignErr error 35 VerifyErr error 36 ComputeMACValue []byte 37 ComputeMACErr error 38 VerifyMACErr error 39 WrapValue *cryptoapi.RecipientWrappedKey 40 WrapError error 41 UnwrapValue []byte 42 UnwrapError error 43 BBSSignValue []byte 44 BBSSignKey []byte 45 BBSSignFn BBSSignFunc 46 BBSSignErr error 47 BBSVerifyErr error 48 VerifyProofErr error 49 DeriveProofValue []byte 50 DeriveProofKey []byte 51 DeriveProofFn DeriveProofFunc 52 DeriveProofError error 53 BlindValue [][]byte 54 BlindError error 55 GetCorrectnessProofValue []byte 56 GetCorrectnessProofError error 57 SignWithSecretsValue []byte 58 SignWithSecretsProof []byte 59 SignWithSecretsError error 60 } 61 62 // Encrypt returns mocked values and a mocked error. 63 func (c *Crypto) Encrypt(msg, aad []byte, kh interface{}) ([]byte, []byte, error) { 64 return c.EncryptValue, c.EncryptNonceValue, c.EncryptErr 65 } 66 67 // Decrypt returns a mocked value and a mocked error. 68 func (c *Crypto) Decrypt(cipher, aad, nonce []byte, kh interface{}) ([]byte, error) { 69 return c.DecryptValue, c.DecryptErr 70 } 71 72 // Sign returns a mocked value and a mocked error. 73 func (c *Crypto) Sign(msg []byte, kh interface{}) ([]byte, error) { 74 if c.SignFn != nil { 75 return c.SignFn(msg, c.SignKey) 76 } 77 78 return c.SignValue, c.SignErr 79 } 80 81 // Verify returns a mocked value. 82 func (c *Crypto) Verify(signature, msg []byte, kh interface{}) error { 83 return c.VerifyErr 84 } 85 86 // ComputeMAC returns a mocked value and a mocked error. 87 func (c *Crypto) ComputeMAC(data []byte, kh interface{}) ([]byte, error) { 88 return c.ComputeMACValue, c.ComputeMACErr 89 } 90 91 // VerifyMAC returns a mocked value. 92 func (c *Crypto) VerifyMAC(mac, data []byte, kh interface{}) error { 93 return c.VerifyMACErr 94 } 95 96 // WrapKey returns a mocked value. 97 func (c *Crypto) WrapKey(cek, apu, apv []byte, recPubKey *cryptoapi.PublicKey, 98 wrapKeyOpts ...cryptoapi.WrapKeyOpts) (*cryptoapi.RecipientWrappedKey, error) { 99 return c.WrapValue, c.WrapError 100 } 101 102 // UnwrapKey returns a mocked value. 103 func (c *Crypto) UnwrapKey(recWK *cryptoapi.RecipientWrappedKey, kh interface{}, 104 wrapKeyOpts ...cryptoapi.WrapKeyOpts) ([]byte, error) { 105 return c.UnwrapValue, c.UnwrapError 106 } 107 108 // SignMulti returns a mocked BBS+ signature value and a mocked error. 109 func (c *Crypto) SignMulti(messages [][]byte, kh interface{}) ([]byte, error) { 110 if c.BBSSignFn != nil { 111 return c.BBSSignFn(messages, c.BBSSignKey) 112 } 113 114 return c.BBSSignValue, c.BBSSignErr 115 } 116 117 // VerifyMulti returns a mocked BBS+ verify result. 118 // returns: 119 // 120 // error in case of errors or nil if signature verification was successful 121 func (c *Crypto) VerifyMulti(messages [][]byte, signature []byte, kh interface{}) error { 122 return c.BBSVerifyErr 123 } 124 125 // VerifyProof returns a mocked BBS+ verify signature proof result. 126 // returns: 127 // 128 // error in case of errors or nil if signature proof verification was successful 129 func (c *Crypto) VerifyProof(revealedMessages [][]byte, proof, nonce []byte, signerPubKH interface{}) error { 130 return c.VerifyProofErr 131 } 132 133 // DeriveProof returns a mocked BBS+ signature proof value and a mocked error. 134 // returns: 135 // 136 // signature proof in []byte 137 // error in case of errors 138 func (c *Crypto) DeriveProof(messages [][]byte, bbsSignature, nonce []byte, revealedIndexes []int, 139 signerPubKH interface{}) ([]byte, error) { 140 if c.DeriveProofFn != nil { 141 return c.DeriveProofFn(messages, bbsSignature, nonce, revealedIndexes, c.DeriveProofKey) 142 } 143 144 return c.DeriveProofValue, c.DeriveProofError 145 }