testutil

package
v1.3.0-rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2019 License: Apache-2.0 Imports: 21 Imported by: 5

Documentation

Overview

Package testutil provides common methods needed in test code.

Index

Constants

View Source
const (

	// AESCTRHMACAEADKeyVersion is the maxmimal version of AES-CTR-HMAC-AEAD keys that Tink supports.
	AESCTRHMACAEADKeyVersion = 0
	// AESCTRHMACAEADTypeURL is the type URL of AES-CTR-HMAC-AEAD keys that Tink supports.
	AESCTRHMACAEADTypeURL = "type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey"

	// AESGCMKeyVersion is the maxmimal version of AES-GCM keys.
	AESGCMKeyVersion = 0
	// AESGCMTypeURL is the type URL of AES-GCM keys that Tink supports.
	AESGCMTypeURL = "type.googleapis.com/google.crypto.tink.AesGcmKey"

	// ChaCha20Poly1305KeyVersion is the maxmimal version of ChaCha20Poly1305 keys that Tink supports.
	ChaCha20Poly1305KeyVersion = 0
	// ChaCha20Poly1305TypeURL is the type URL of ChaCha20Poly1305 keys.
	ChaCha20Poly1305TypeURL = "type.googleapis.com/google.crypto.tink.ChaCha20Poly1305Key"

	// KMSEnvelopeAEADKeyVersion is the maxmimal version of KMSEnvelopeAEAD keys that Tink supports.
	KMSEnvelopeAEADKeyVersion = 0
	// KMSEnvelopeAEADTypeURL is the type URL of KMSEnvelopeAEAD keys.
	KMSEnvelopeAEADTypeURL = "type.googleapis.com/google.crypto.tink.KmsEnvelopeAeadKey"

	// XChaCha20Poly1305KeyVersion is the maxmimal version of XChaCha20Poly1305 keys that Tink supports.
	XChaCha20Poly1305KeyVersion = 0
	// XChaCha20Poly1305TypeURL is the type URL of XChaCha20Poly1305 keys.
	XChaCha20Poly1305TypeURL = "type.googleapis.com/google.crypto.tink.XChaCha20Poly1305Key"

	// EciesAeadHkdfPrivateKeyKeyVersion is the maxmimal version of keys that this key manager supports.
	EciesAeadHkdfPrivateKeyKeyVersion = 0

	// EciesAeadHkdfPrivateKeyTypeURL is the url that this key manager supports.
	EciesAeadHkdfPrivateKeyTypeURL = "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey"

	// EciesAeadHkdfPublicKeyKeyVersion is the maxmimal version of keys that this key manager supports.
	EciesAeadHkdfPublicKeyKeyVersion = 0

	// EciesAeadHkdfPublicKeyTypeURL is the url that this key manager supports.
	EciesAeadHkdfPublicKeyTypeURL = "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPublicKey"

	// AESSIVKeyVersion is the maxmimal version of AES-SIV keys that Tink supports.
	AESSIVKeyVersion = 0
	// AESSIVTypeURL is the type URL of AES-SIV keys.
	AESSIVTypeURL = "type.googleapis.com/google.crypto.tink.AesSivKey"

	// HMACKeyVersion is the maxmimal version of HMAC keys that Tink supports.
	HMACKeyVersion = 0
	// HMACTypeURL is the type URL of HMAC keys.
	HMACTypeURL = "type.googleapis.com/google.crypto.tink.HmacKey"

	// ECDSASignerKeyVersion is the maximum version of ECDSA private keys that Tink supports.
	ECDSASignerKeyVersion = 0
	// ECDSASignerTypeURL is the type URL of ECDSA private keys.
	ECDSASignerTypeURL = "type.googleapis.com/google.crypto.tink.EcdsaPrivateKey"

	// ECDSAVerifierKeyVersion is the maximum version of ECDSA public keys that Tink supports.
	ECDSAVerifierKeyVersion = 0
	// ECDSAVerifierTypeURL is the type URL of ECDSA public keys.
	ECDSAVerifierTypeURL = "type.googleapis.com/google.crypto.tink.EcdsaPublicKey"

	// ED25519SignerKeyVersion is the maximum version of ED25519 private keys that Tink supports.
	ED25519SignerKeyVersion = 0
	// ED25519SignerTypeURL is the type URL of ED25519 private keys.
	ED25519SignerTypeURL = "type.googleapis.com/google.crypto.tink.Ed25519PrivateKey"

	// ED25519VerifierKeyVersion is the maximum version of ED25519 public keys that Tink supports.
	ED25519VerifierKeyVersion = 0
	// ED25519VerifierTypeURL is the type URL of ED25519 public keys.
	ED25519VerifierTypeURL = "type.googleapis.com/google.crypto.tink.Ed25519PublicKey"
)

Variables

This section is empty.

Functions

func GenerateECIESAEADHKDFPrivateKey added in v1.3.0

func GenerateECIESAEADHKDFPrivateKey(c commonpb.EllipticCurveType, ht commonpb.HashType, ptfmt commonpb.EcPointFormat, dekT *tinkpb.KeyTemplate, salt []byte) (*eciespb.EciesAeadHkdfPrivateKey, error)

GenerateECIESAEADHKDFPrivateKey generates a new EC key pair and returns the private key proto.

func GenerateMutations added in v1.3.0

func GenerateMutations(src []byte) (all [][]byte)

GenerateMutations generates different byte mutations for a given byte array.

func GetECDSAParamNames added in v1.3.0

func GetECDSAParamNames(params *ecdsapb.EcdsaParams) (string, string, string)

GetECDSAParamNames returns the string representations of each parameter in the given ECDSAParams.

func NewAESGCMKey added in v1.3.0

func NewAESGCMKey(keyVersion uint32, keySize uint32) *gcmpb.AesGcmKey

NewAESGCMKey creates a randomly generated AESGCMKey.

func NewAESGCMKeyData added in v1.3.0

func NewAESGCMKeyData(keySize uint32) *tinkpb.KeyData

NewAESGCMKeyData creates a KeyData containing a randomly generated AESGCMKey.

func NewAESGCMKeyFormat added in v1.3.0

func NewAESGCMKeyFormat(keySize uint32) *gcmpb.AesGcmKeyFormat

NewAESGCMKeyFormat returns a new AESGCMKeyFormat.

func NewDummyKey

func NewDummyKey(keyID int, status tinkpb.KeyStatusType, outputPrefixType tinkpb.OutputPrefixType) *tinkpb.Keyset_Key

NewDummyKey returns a dummy key that doesn't contain actual key material.

func NewECDSAKeyFormat added in v1.3.0

func NewECDSAKeyFormat(params *ecdsapb.EcdsaParams) *ecdsapb.EcdsaKeyFormat

NewECDSAKeyFormat creates a ECDSAKeyFormat with the specified parameters.

func NewECDSAParams added in v1.3.0

NewECDSAParams creates a ECDSAParams with the specified parameters.

func NewECDSAPrivateKey added in v1.3.0

func NewECDSAPrivateKey(version uint32,
	publicKey *ecdsapb.EcdsaPublicKey,
	keyValue []byte) *ecdsapb.EcdsaPrivateKey

NewECDSAPrivateKey creates a ECDSAPrivateKey with the specified paramaters.

func NewECDSAPublicKey added in v1.3.0

func NewECDSAPublicKey(version uint32,
	params *ecdsapb.EcdsaParams,
	x []byte, y []byte) *ecdsapb.EcdsaPublicKey

NewECDSAPublicKey creates a ECDSAPublicKey with the specified paramaters.

func NewED25519PrivateKey added in v1.3.0

func NewED25519PrivateKey() *ed25519pb.Ed25519PrivateKey

NewED25519PrivateKey creates an ED25519PrivateKey with a randomly generated key material.

func NewED25519PrivateKeyData added in v1.3.0

func NewED25519PrivateKeyData() *tinkpb.KeyData

NewED25519PrivateKeyData creates a KeyData containing an ED25519PrivateKey with a randomly generated key material.

func NewED25519PublicKey added in v1.3.0

func NewED25519PublicKey() *ed25519pb.Ed25519PublicKey

NewED25519PublicKey creates an ED25519PublicKey with a randomly generated key material.

func NewEncryptedKeyset added in v1.3.0

func NewEncryptedKeyset(encryptedKeySet []byte, info *tinkpb.KeysetInfo) *tinkpb.EncryptedKeyset

NewEncryptedKeyset creates a new EncryptedKeyset with a specified parameters.

func NewHMACKey added in v1.3.0

func NewHMACKey(hashType commonpb.HashType, tagSize uint32) *hmacpb.HmacKey

NewHMACKey creates a new HMACKey with the specified parameters.

func NewHMACKeyData added in v1.3.0

func NewHMACKeyData(hashType commonpb.HashType, tagSize uint32) *tinkpb.KeyData

NewHMACKeyData returns a new KeyData that contains a HMACKey.

func NewHMACKeyFormat added in v1.3.0

func NewHMACKeyFormat(hashType commonpb.HashType, tagSize uint32) *hmacpb.HmacKeyFormat

NewHMACKeyFormat creates a new HMACKeyFormat with the specified parameters.

func NewHMACKeysetManager added in v1.3.0

func NewHMACKeysetManager() *keyset.Manager

NewHMACKeysetManager returns a new KeysetManager that contains a HMACKey.

func NewHMACParams added in v1.3.0

func NewHMACParams(hashType commonpb.HashType, tagSize uint32) *hmacpb.HmacParams

NewHMACParams returns a new HMACParams.

func NewKey added in v1.3.0

func NewKey(keyData *tinkpb.KeyData,
	status tinkpb.KeyStatusType,
	keyID uint32,
	prefixType tinkpb.OutputPrefixType) *tinkpb.Keyset_Key

NewKey creates a new Key with the specified parameters.

func NewKeyData added in v1.3.0

func NewKeyData(typeURL string,
	value []byte,
	materialType tinkpb.KeyData_KeyMaterialType) *tinkpb.KeyData

NewKeyData creates a new KeyData with the specified parameters.

func NewKeyset added in v1.3.0

func NewKeyset(primaryKeyID uint32,
	keys []*tinkpb.Keyset_Key) *tinkpb.Keyset

NewKeyset creates a new Keyset with the specified parameters.

func NewRandomECDSAPrivateKey added in v1.3.0

func NewRandomECDSAPrivateKey(hashType commonpb.HashType, curve commonpb.EllipticCurveType) *ecdsapb.EcdsaPrivateKey

NewRandomECDSAPrivateKey creates an ECDSAPrivateKey with a randomly generated key material.

func NewRandomECDSAPrivateKeyData added in v1.3.0

func NewRandomECDSAPrivateKeyData(hashType commonpb.HashType, curve commonpb.EllipticCurveType) *tinkpb.KeyData

NewRandomECDSAPrivateKeyData creates a KeyData containing an ECDSAPrivateKey with a randomly generated key material.

func NewRandomECDSAPublicKey added in v1.3.0

func NewRandomECDSAPublicKey(hashType commonpb.HashType, curve commonpb.EllipticCurveType) *ecdsapb.EcdsaPublicKey

NewRandomECDSAPublicKey creates an ECDSAPublicKe with a randomly generated key material.

func NewSerializedAESGCMKey added in v1.3.0

func NewSerializedAESGCMKey(keySize uint32) []byte

NewSerializedAESGCMKey creates a AESGCMKey with randomly generated key material.

func NewTestAESGCMKeyset added in v1.3.0

func NewTestAESGCMKeyset(primaryOutputPrefixType tinkpb.OutputPrefixType) *tinkpb.Keyset

NewTestAESGCMKeyset creates a new Keyset containing an AESGCMKey.

func NewTestAESSIVKeyset added in v1.3.0

func NewTestAESSIVKeyset(primaryOutputPrefixType tinkpb.OutputPrefixType) *tinkpb.Keyset

NewTestAESSIVKeyset creates a new Keyset containing an AesSivKey.

func NewTestHMACKeyset added in v1.3.0

func NewTestHMACKeyset(tagSize uint32,
	primaryOutputPrefixType tinkpb.OutputPrefixType) *tinkpb.Keyset

NewTestHMACKeyset creates a new Keyset containing a HMACKey.

func NewTestKeyset

func NewTestKeyset(keyData *tinkpb.KeyData,
	primaryOutputPrefixType tinkpb.OutputPrefixType) *tinkpb.Keyset

NewTestKeyset creates a new test Keyset.

Types

type DummyAEAD added in v1.3.0

type DummyAEAD struct{}

DummyAEAD is a dummy implementation of AEAD interface.

func (*DummyAEAD) Decrypt added in v1.3.0

func (a *DummyAEAD) Decrypt(ciphertext []byte, additionalData []byte) ([]byte, error)

Decrypt decrypts the ciphertext.

func (*DummyAEAD) Encrypt added in v1.3.0

func (a *DummyAEAD) Encrypt(plaintext []byte, additionalData []byte) ([]byte, error)

Encrypt encrypts the plaintext.

type DummyAEADKeyManager added in v1.3.0

type DummyAEADKeyManager struct{}

DummyAEADKeyManager is a dummy implementation of the KeyManager interface. It returns DummyAEAD when GetPrimitive() functions are called.

func (*DummyAEADKeyManager) DoesSupport added in v1.3.0

func (km *DummyAEADKeyManager) DoesSupport(typeURL string) bool

DoesSupport returns true iff this KeyManager supports key type identified by typeURL.

func (*DummyAEADKeyManager) NewKey added in v1.3.0

func (km *DummyAEADKeyManager) NewKey(serializedKeyFormat []byte) (proto.Message, error)

NewKey generates a new key according to specification in serializedKeyFormat.

func (*DummyAEADKeyManager) NewKeyData added in v1.3.0

func (km *DummyAEADKeyManager) NewKeyData(serializedKeyFormat []byte) (*tinkpb.KeyData, error)

NewKeyData generates a new KeyData according to specification in serializedkeyFormat.

func (*DummyAEADKeyManager) Primitive added in v1.3.0

func (km *DummyAEADKeyManager) Primitive(serializedKey []byte) (interface{}, error)

Primitive constructs a primitive instance for the key given in serializedKey, which must be a serialized key protocol buffer handled by this manager.

func (*DummyAEADKeyManager) TypeURL added in v1.3.0

func (km *DummyAEADKeyManager) TypeURL() string

TypeURL returns the type URL.

type DummyKMSClient added in v1.3.0

type DummyKMSClient struct{}

DummyKMSClient is a dummy implementation of a KMS Client.

func (*DummyKMSClient) GetAEAD added in v1.3.0

func (d *DummyKMSClient) GetAEAD(keyURI string) (tink.AEAD, error)

GetAEAD gets an Aead backend by keyURI.

func (*DummyKMSClient) LoadCredentials added in v1.3.0

func (d *DummyKMSClient) LoadCredentials(credentialPath string) (interface{}, error)

LoadCredentials loads the credentials in credentialPath. If credentialPath is null, loads the default credentials.

func (*DummyKMSClient) LoadDefaultCredentials added in v1.3.0

func (d *DummyKMSClient) LoadDefaultCredentials() (interface{}, error)

LoadDefaultCredentials loads with the default credentials.

func (*DummyKMSClient) Supported added in v1.3.0

func (d *DummyKMSClient) Supported(keyURI string) bool

Supported true if this client does support keyURI

type DummyMAC added in v1.3.0

type DummyMAC struct {
	Name string
}

DummyMAC is a dummy implementation of Mac interface.

func (*DummyMAC) ComputeMAC added in v1.3.0

func (h *DummyMAC) ComputeMAC(data []byte) ([]byte, error)

ComputeMAC computes message authentication code (MAC) for {@code data}.

func (*DummyMAC) VerifyMAC added in v1.3.0

func (h *DummyMAC) VerifyMAC(mac []byte, data []byte) error

VerifyMAC verifies whether {@code mac} is a correct authentication code (MAC) for {@code data}.

type WycheproofCase added in v1.3.0

type WycheproofCase struct {
	CaseID  int      `json:"tcId"`
	Comment string   `json:"comment"`
	Result  string   `json:"result"`
	Flags   []string `json:"flags"`
}

WycheproofCase represents the common elements of a tests object in a Wycheproof group. Implementation should embed WycheproofCase in a struct that contains fields specific to the test type. See wycheproofutil_test.go for an example.

type WycheproofGroup added in v1.3.0

type WycheproofGroup struct {
	Type string `json:"type"`
}

WycheproofGroup represents the common elements of a testGroups object in a Wycheproof suite. Implementations should embed WycheproofGroup in a struct that strongly types its list of cases. See wycheproofutil_test.go for an example.

type WycheproofSuite added in v1.3.0

type WycheproofSuite struct {
	Algorithm        string            `json:"algorithm"`
	GeneratorVersion string            `json:"generatorVersion"`
	NumberOfTests    int               `json:"numberOfTests"`
	Notes            map[string]string `json:"notes"`
}

WycheproofSuite represents the common elements of the top level object in a Wycheproof json file. Implementations should embed WycheproofSuite in a struct that strongly types the testGroups field. See wycheproofutil_test.go for an example.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL