Search in sources :

Example 1 with OutputPrefixType

use of com.google.crypto.tink.proto.OutputPrefixType in project tink by google.

the class KeysetManager method newKey.

@GuardedBy("this")
private synchronized Keyset.Key newKey(KeyTemplate keyTemplate) throws GeneralSecurityException {
    KeyData keyData = Registry.newKeyData(keyTemplate);
    int keyId = newKeyId();
    OutputPrefixType outputPrefixType = keyTemplate.getOutputPrefixType();
    if (outputPrefixType == OutputPrefixType.UNKNOWN_PREFIX) {
        outputPrefixType = OutputPrefixType.TINK;
    }
    return Keyset.Key.newBuilder().setKeyData(keyData).setKeyId(keyId).setStatus(KeyStatusType.ENABLED).setOutputPrefixType(outputPrefixType).build();
}
Also used : OutputPrefixType(com.google.crypto.tink.proto.OutputPrefixType) KeyData(com.google.crypto.tink.proto.KeyData) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 2 with OutputPrefixType

use of com.google.crypto.tink.proto.OutputPrefixType in project tink by google.

the class SignatureKeyTemplatesTest method createEcdsaKeyTemplate.

@Test
public void createEcdsaKeyTemplate() throws Exception {
    // Intentionally using "weird" or invalid values for parameters,
    // to test that the function correctly puts them in the resulting template.
    HashType hashType = HashType.SHA512;
    EllipticCurveType curve = EllipticCurveType.UNKNOWN_CURVE;
    EcdsaSignatureEncoding encoding = EcdsaSignatureEncoding.IEEE_P1363;
    OutputPrefixType prefixType = OutputPrefixType.TINK;
    KeyTemplate template = SignatureKeyTemplates.createEcdsaKeyTemplate(hashType, curve, encoding, prefixType);
    assertEquals(new EcdsaSignKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    EcdsaKeyFormat format = EcdsaKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertEquals(hashType, format.getParams().getHashType());
    assertEquals(curve, format.getParams().getCurve());
    assertEquals(encoding, format.getParams().getEncoding());
}
Also used : OutputPrefixType(com.google.crypto.tink.proto.OutputPrefixType) EcdsaKeyFormat(com.google.crypto.tink.proto.EcdsaKeyFormat) HashType(com.google.crypto.tink.proto.HashType) EcdsaSignatureEncoding(com.google.crypto.tink.proto.EcdsaSignatureEncoding) EllipticCurveType(com.google.crypto.tink.proto.EllipticCurveType) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Aggregations

OutputPrefixType (com.google.crypto.tink.proto.OutputPrefixType)2 EcdsaKeyFormat (com.google.crypto.tink.proto.EcdsaKeyFormat)1 EcdsaSignatureEncoding (com.google.crypto.tink.proto.EcdsaSignatureEncoding)1 EllipticCurveType (com.google.crypto.tink.proto.EllipticCurveType)1 HashType (com.google.crypto.tink.proto.HashType)1 KeyData (com.google.crypto.tink.proto.KeyData)1 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)1 GuardedBy (javax.annotation.concurrent.GuardedBy)1 Test (org.junit.Test)1