@Test public void test_wrapMultiple_works() throws Exception { PrimitiveSet<JwtMac> primitiveSet = PrimitiveSet.newPrimitiveSet(JwtMac.class); JwtMac mac1 = new JwtHmac("HS256", new SecretKeySpec(Random.randBytes(32), "HMAC")); primitiveSet.addPrimitive( mac1, Keyset.Key.newBuilder() .setKeyId(202020) .setStatus(KeyStatusType.ENABLED) .setOutputPrefixType(OutputPrefixType.RAW) .build()); JwtMac mac2 = new JwtHmac("HS256", new SecretKeySpec(Random.randBytes(32), "HMAC")); PrimitiveSet.Entry<JwtMac> entry = primitiveSet.addPrimitive( mac2, Keyset.Key.newBuilder() .setKeyId(202021) .setStatus(KeyStatusType.ENABLED) .setOutputPrefixType(OutputPrefixType.RAW) .build()); primitiveSet.setPrimary(entry); JwtMac wrapped = wrapper.wrap(primitiveSet); ToBeSignedJwt tbs = new ToBeSignedJwt.Builder().setJwtId("blah").build(); String compact = wrapped.createCompact(tbs); JwtValidator validator = new JwtValidator.Builder().build(); Jwt token = wrapped.verifyCompact(compact, validator); Jwt token2 = mac2.verifyCompact(compact, validator); assertThrows(GeneralSecurityException.class, () -> mac1.verifyCompact(compact, validator)); assertThat(token.getJwtId()).isEqualTo("blah"); assertThat(token.getAlgorithm()).isEqualTo("HS256"); assertThat(token2.getJwtId()).isEqualTo("blah"); assertThat(token2.getAlgorithm()).isEqualTo("HS256"); }
@Override public JwtMac wrap(final PrimitiveSet<JwtMac> primitives) throws GeneralSecurityException { validate(primitives); return new WrappedJwtMac(primitives); }
JwtMacWrapper implements PrimitiveWrapper<JwtMac, JwtMac> { @Override public JwtMac wrap(final PrimitiveSet<JwtMac> primitives) throws GeneralSecurityException { validate(primitives); return new WrappedJwtMac(primitives); } }
JwtMacWrapper implements PrimitiveWrapper<JwtMac, JwtMac> { @Override public JwtMac wrap(final PrimitiveSet<JwtMac> primitives) throws GeneralSecurityException { validate(primitives); return new WrappedJwtMac(primitives); } JwtMacWrapper(); }
JwtMacWrapper implements PrimitiveWrapper<JwtMac, JwtMac> { @Override public JwtMac wrap(final PrimitiveSet<JwtMac> primitives) throws GeneralSecurityException { validate(primitives); return new WrappedJwtMac(primitives); } JwtMacWrapper(); @Override JwtMac wrap(final PrimitiveSet<JwtMac> primitives); @Override Class<JwtMac> getPrimitiveClass(); @Override Class<JwtMac> getInputPrimitiveClass(); static void register(); }
JwtMacWrapper implements PrimitiveWrapper<JwtMac, JwtMac> { @Override public JwtMac wrap(final PrimitiveSet<JwtMac> primitives) throws GeneralSecurityException { validate(primitives); return new WrappedJwtMac(primitives); } JwtMacWrapper(); @Override JwtMac wrap(final PrimitiveSet<JwtMac> primitives); @Override Class<JwtMac> getPrimitiveClass(); @Override Class<JwtMac> getInputPrimitiveClass(); static void register();  }