test_class.file: java_src/src/test/java/com/google/crypto/tink/signature/PublicKeySignFactoryTest.java
test_class.identifier: PublicKeySignFactoryTest
test_case.body: @Test
    public void testMultipleKeys() throws Exception {
      EcdsaPrivateKey tinkPrivateKey =
          TestUtil.generateEcdsaPrivKey(
              EllipticCurveType.NIST_P521, HashType.SHA512, EcdsaSignatureEncoding.DER);
      Key tink =
          TestUtil.createKey(
              TestUtil.createKeyData(
                  tinkPrivateKey,
                  new EcdsaSignKeyManager().getKeyType(),
                  KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE),
              1,
              KeyStatusType.ENABLED,
              OutputPrefixType.TINK);
  
      EcdsaPrivateKey legacyPrivateKey =
          TestUtil.generateEcdsaPrivKey(
              EllipticCurveType.NIST_P256, HashType.SHA256, EcdsaSignatureEncoding.DER);
      Key legacy =
          TestUtil.createKey(
              TestUtil.createKeyData(
                  legacyPrivateKey,
                  new EcdsaSignKeyManager().getKeyType(),
                  KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE),
              2,
              KeyStatusType.ENABLED,
              OutputPrefixType.LEGACY);
  
      EcdsaPrivateKey rawPrivateKey =
          TestUtil.generateEcdsaPrivKey(
              EllipticCurveType.NIST_P384, HashType.SHA512, EcdsaSignatureEncoding.DER);
      Key raw =
          TestUtil.createKey(
              TestUtil.createKeyData(
                  rawPrivateKey,
                  new EcdsaSignKeyManager().getKeyType(),
                  KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE),
              3,
              KeyStatusType.ENABLED,
              OutputPrefixType.RAW);
  
      EcdsaPrivateKey crunchyPrivateKey =
          TestUtil.generateEcdsaPrivKey(
              EllipticCurveType.NIST_P384, HashType.SHA512, EcdsaSignatureEncoding.DER);
      Key crunchy =
          TestUtil.createKey(
              TestUtil.createKeyData(
                  crunchyPrivateKey,
                  new EcdsaSignKeyManager().getKeyType(),
                  KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE),
              4,
              KeyStatusType.ENABLED,
              OutputPrefixType.CRUNCHY);
  
      Key[] keys = new Key[] {tink, legacy, raw, crunchy};
      EcdsaPrivateKey[] privateKeys =
          new EcdsaPrivateKey[] {tinkPrivateKey, legacyPrivateKey, rawPrivateKey, crunchyPrivateKey};
  
      int j = keys.length;
      for (int i = 0; i < j; i++) {
        KeysetHandle keysetHandle =
            TestUtil.createKeysetHandle(
                TestUtil.createKeyset(
                    keys[i], keys[(i + 1) % j], keys[(i + 2) % j], keys[(i + 3) % j]));
        // Signs with the primary private key.
        PublicKeySign signer = PublicKeySignFactory.getPrimitive(keysetHandle);
        byte[] plaintext = Random.randBytes(1211);
        byte[] sig = signer.sign(plaintext);
        if (keys[i].getOutputPrefixType() != OutputPrefixType.RAW) {
          byte[] prefix = Arrays.copyOfRange(sig, 0, CryptoFormat.NON_RAW_PREFIX_SIZE);
          assertArrayEquals(prefix, CryptoFormat.getOutputPrefix(keys[i]));
        }
  
        // Verifying with the primary public key should work.
        PublicKeyVerify verifier =
            PublicKeyVerifyFactory.getPrimitive(
                TestUtil.createKeysetHandle(
                    TestUtil.createKeyset(
                        TestUtil.createKey(
                            TestUtil.createKeyData(
                                privateKeys[i].getPublicKey(),
                                new EcdsaVerifyKeyManager().getKeyType(),
                                KeyData.KeyMaterialType.ASYMMETRIC_PUBLIC),
                            keys[i].getKeyId(),
                            KeyStatusType.ENABLED,
                            keys[i].getOutputPrefixType()))));
        try {
          verifier.verify(sig, plaintext);
        } catch (GeneralSecurityException ex) {
          fail("Valid signature, should not throw exception");
        }
  
        // Verifying with a random public key should fail.
        EcdsaPrivateKey randomPrivKey =
            TestUtil.generateEcdsaPrivKey(
                EllipticCurveType.NIST_P521, HashType.SHA512, EcdsaSignatureEncoding.DER);
        verifier =
            PublicKeyVerifyFactory.getPrimitive(
                TestUtil.createKeysetHandle(
                    TestUtil.createKeyset(
                        TestUtil.createKey(
                            TestUtil.createKeyData(
                                randomPrivKey.getPublicKey(),
                                new EcdsaVerifyKeyManager().getKeyType(),
                                KeyData.KeyMaterialType.ASYMMETRIC_PUBLIC),
                            keys[i].getKeyId(),
                            KeyStatusType.ENABLED,
                            keys[i].getOutputPrefixType()))));
        try {
          verifier.verify(sig, plaintext);
          fail("Invalid signature, should have thrown exception");
        } catch (GeneralSecurityException expected) {
          // Expected
        }
      }
    }
test_case.class_method_signature: PublicKeySignFactoryTest.testMultipleKeys()
test_case.full_signature: @Test public void testMultipleKeys()
test_case.identifier: testMultipleKeys
test_case.invocations: generateEcdsaPrivKey createKey createKeyData getKeyType generateEcdsaPrivKey createKey createKeyData getKeyType generateEcdsaPrivKey createKey createKeyData getKeyType generateEcdsaPrivKey createKey createKeyData getKeyType createKeysetHandle createKeyset getPrimitive randBytes sign getOutputPrefixType copyOfRange assertArrayEquals getOutputPrefix getPrimitive createKeysetHandle createKeyset createKey createKeyData getPublicKey getKeyType getKeyId getOutputPrefixType verify fail generateEcdsaPrivKey getPrimitive createKeysetHandle createKeyset createKey createKeyData getPublicKey getKeyType getKeyId getOutputPrefixType verify fail
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMultipleKeys()
focal_class.file: java_src/src/main/java/com/google/crypto/tink/signature/PublicKeySignFactory.java
focal_class.identifier: PublicKeySignFactory
focal_class.class_method_signature: PublicKeySignFactory.getPrimitive(KeysetHandle keysetHandle)
focal_class.full_signature: @Deprecated public static PublicKeySign getPrimitive(KeysetHandle keysetHandle)
focal_class.identifier: getPrimitive
focal_class.modifiers: @Deprecated public static
focal_class.parameters: (KeysetHandle keysetHandle)
focal_class.return: PublicKeySign
focal_class.signature: PublicKeySign getPrimitive(KeysetHandle keysetHandle)
focal_class.class_method_signature: PublicKeySignFactory.getPrimitive(
        KeysetHandle keysetHandle, final KeyManager<PublicKeySign> keyManager)
focal_class.full_signature: @Deprecated public static PublicKeySign getPrimitive(
        KeysetHandle keysetHandle, final KeyManager<PublicKeySign> keyManager)
focal_class.identifier: getPrimitive
focal_class.modifiers: @Deprecated public static
focal_class.parameters: (
        KeysetHandle keysetHandle, final KeyManager<PublicKeySign> keyManager)
focal_class.return: PublicKeySign
focal_class.signature: PublicKeySign getPrimitive(
        KeysetHandle keysetHandle, final KeyManager<PublicKeySign> keyManager)
focal_method.body: @Deprecated
    public static PublicKeySign getPrimitive(KeysetHandle keysetHandle)
        throws GeneralSecurityException {
      return getPrimitive(keysetHandle, /* keyManager= */ null);
    }
focal_method.class_method_signature: PublicKeySignFactory.getPrimitive(KeysetHandle keysetHandle)
focal_method.full_signature: @Deprecated public static PublicKeySign getPrimitive(KeysetHandle keysetHandle)
focal_method.identifier: getPrimitive
focal_method.invocations: getPrimitive
focal_method.modifiers: @Deprecated public static
focal_method.parameters: (KeysetHandle keysetHandle)
focal_method.return: PublicKeySign
focal_method.signature: PublicKeySign getPrimitive(KeysetHandle keysetHandle)