test_class.file: java_src/src/test/java/com/google/crypto/tink/signature/PublicKeyVerifyWrapperTest.java
test_class.identifier: PublicKeyVerifyWrapperTest
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.getPublicKey(),
                  new EcdsaVerifyKeyManager().getKeyType(),
                  KeyData.KeyMaterialType.ASYMMETRIC_PUBLIC),
              1,
              KeyStatusType.ENABLED,
              OutputPrefixType.TINK);
  
      EcdsaPrivateKey legacyPrivateKey =
          TestUtil.generateEcdsaPrivKey(
              EllipticCurveType.NIST_P256, HashType.SHA256, EcdsaSignatureEncoding.DER);
      Key legacy =
          TestUtil.createKey(
              TestUtil.createKeyData(
                  legacyPrivateKey.getPublicKey(),
                  new EcdsaVerifyKeyManager().getKeyType(),
                  KeyData.KeyMaterialType.ASYMMETRIC_PUBLIC),
              2,
              KeyStatusType.ENABLED,
              OutputPrefixType.LEGACY);
  
      EcdsaPrivateKey rawPrivateKey =
          TestUtil.generateEcdsaPrivKey(
              EllipticCurveType.NIST_P384, HashType.SHA512, EcdsaSignatureEncoding.DER);
      Key raw =
          TestUtil.createKey(
              TestUtil.createKeyData(
                  rawPrivateKey.getPublicKey(),
                  new EcdsaVerifyKeyManager().getKeyType(),
                  KeyData.KeyMaterialType.ASYMMETRIC_PUBLIC),
              3,
              KeyStatusType.ENABLED,
              OutputPrefixType.RAW);
  
      EcdsaPrivateKey crunchyPrivateKey =
          TestUtil.generateEcdsaPrivKey(
              EllipticCurveType.NIST_P384, HashType.SHA512, EcdsaSignatureEncoding.DER);
      Key crunchy =
          TestUtil.createKey(
              TestUtil.createKeyData(
                  crunchyPrivateKey.getPublicKey(),
                  new EcdsaVerifyKeyManager().getKeyType(),
                  KeyData.KeyMaterialType.ASYMMETRIC_PUBLIC),
              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]));
        PublicKeyVerify verifier =
            new PublicKeyVerifyWrapper()
                .wrap(Registry.getPrimitives(keysetHandle, PublicKeyVerify.class));
        // Signature from any keys in the keyset should be valid.
        for (int k = 0; k < j; k++) {
          PublicKeySign signer =
              PublicKeySignFactory.getPrimitive(
                  TestUtil.createKeysetHandle(
                      TestUtil.createKeyset(
                          TestUtil.createKey(
                              TestUtil.createKeyData(
                                  privateKeys[k],
                                  new EcdsaSignKeyManager().getKeyType(),
                                  KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE),
                              keys[k].getKeyId(),
                              KeyStatusType.ENABLED,
                              keys[k].getOutputPrefixType()))));
          byte[] plaintext = Random.randBytes(1211);
          byte[] sig = signer.sign(plaintext);
          try {
            verifier.verify(sig, plaintext);
          } catch (GeneralSecurityException ex) {
            fail("Valid signature, should not throw exception: " + k);
          }
        }
  
        // Signature from a random key should be invalid.
        EcdsaPrivateKey randomPrivKey =
            TestUtil.generateEcdsaPrivKey(
                EllipticCurveType.NIST_P521, HashType.SHA512, EcdsaSignatureEncoding.DER);
        PublicKeySign signer =
            PublicKeySignFactory.getPrimitive(
                TestUtil.createKeysetHandle(
                    TestUtil.createKeyset(
                        TestUtil.createKey(
                            TestUtil.createKeyData(
                                randomPrivKey,
                                new EcdsaSignKeyManager().getKeyType(),
                                KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE),
                            1,
                            KeyStatusType.ENABLED,
                            keys[0].getOutputPrefixType()))));
        byte[] plaintext = Random.randBytes(1211);
        byte[] sig = signer.sign(plaintext);
        try {
          verifier.verify(sig, plaintext);
          fail("Invalid signature, should have thrown exception");
        } catch (GeneralSecurityException expected) {
          // Expected
        }
      }
    }
test_case.class_method_signature: PublicKeyVerifyWrapperTest.testMultipleKeys()
test_case.full_signature: @Test public void testMultipleKeys()
test_case.identifier: testMultipleKeys
test_case.invocations: generateEcdsaPrivKey createKey createKeyData getPublicKey getKeyType generateEcdsaPrivKey createKey createKeyData getPublicKey getKeyType generateEcdsaPrivKey createKey createKeyData getPublicKey getKeyType generateEcdsaPrivKey createKey createKeyData getPublicKey getKeyType createKeysetHandle createKeyset wrap getPrimitives getPrimitive createKeysetHandle createKeyset createKey createKeyData getKeyType getKeyId getOutputPrefixType randBytes sign verify fail generateEcdsaPrivKey getPrimitive createKeysetHandle createKeyset createKey createKeyData getKeyType getOutputPrefixType randBytes sign verify fail
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMultipleKeys()
focal_class.declarator: logger = Logger.getLogger(PublicKeyVerifyWrapper.class.getName())
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = Logger.getLogger(PublicKeyVerifyWrapper.class.getName());
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: java_src/src/main/java/com/google/crypto/tink/signature/PublicKeyVerifyWrapper.java
focal_class.identifier: PublicKeyVerifyWrapper
focal_class.interfaces: implements PrimitiveWrapper<PublicKeyVerify, PublicKeyVerify>
focal_class.class_method_signature: PublicKeyVerifyWrapper.wrap(final PrimitiveSet<PublicKeyVerify> primitives)
focal_class.full_signature: @Override public PublicKeyVerify wrap(final PrimitiveSet<PublicKeyVerify> primitives)
focal_class.identifier: wrap
focal_class.modifiers: @Override public
focal_class.parameters: (final PrimitiveSet<PublicKeyVerify> primitives)
focal_class.return: PublicKeyVerify
focal_class.signature: PublicKeyVerify wrap(final PrimitiveSet<PublicKeyVerify> primitives)
focal_class.class_method_signature: PublicKeyVerifyWrapper.getPrimitiveClass()
focal_class.full_signature: @Override public Class<PublicKeyVerify> getPrimitiveClass()
focal_class.identifier: getPrimitiveClass
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Class<PublicKeyVerify>
focal_class.signature: Class<PublicKeyVerify> getPrimitiveClass()
focal_class.class_method_signature: PublicKeyVerifyWrapper.getInputPrimitiveClass()
focal_class.full_signature: @Override public Class<PublicKeyVerify> getInputPrimitiveClass()
focal_class.identifier: getInputPrimitiveClass
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Class<PublicKeyVerify>
focal_class.signature: Class<PublicKeyVerify> getInputPrimitiveClass()
focal_class.class_method_signature: PublicKeyVerifyWrapper.register()
focal_class.full_signature: public static void register()
focal_class.identifier: register
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void register()
focal_method.body: @Override
    public PublicKeyVerify wrap(final PrimitiveSet<PublicKeyVerify> primitives) {
      return new WrappedPublicKeyVerify(primitives);
    }
focal_method.class_method_signature: PublicKeyVerifyWrapper.wrap(final PrimitiveSet<PublicKeyVerify> primitives)
focal_method.full_signature: @Override public PublicKeyVerify wrap(final PrimitiveSet<PublicKeyVerify> primitives)
focal_method.identifier: wrap
focal_method.modifiers: @Override public
focal_method.parameters: (final PrimitiveSet<PublicKeyVerify> primitives)
focal_method.return: PublicKeyVerify
focal_method.signature: PublicKeyVerify wrap(final PrimitiveSet<PublicKeyVerify> primitives)