@Test public void validateKey_notValid_throws() throws Exception { HmacKey validKey = factory.createKey(makeHmacKeyFormat(16, 10, HashType.SHA1)); try { manager.validateKey( HmacKey.newBuilder(validKey) .setKeyValue(ByteString.copyFrom(Random.randBytes(15))) .build()); fail(); } catch (GeneralSecurityException e) { } try { manager .validateKey( HmacKey.newBuilder(validKey) .setParams(HmacParams.newBuilder(validKey.getParams()).setTagSize(0).build()) .build()); fail(); } catch (GeneralSecurityException e) { } try { manager .validateKey( HmacKey.newBuilder(validKey) .setParams(HmacParams.newBuilder(validKey.getParams()).setTagSize(9).build()) .build()); fail(); } catch (GeneralSecurityException e) { } try { manager .validateKey( HmacKey.newBuilder(validKey) .setParams(HmacParams.newBuilder(validKey.getParams()).setTagSize(21).build()) .build()); fail(); } catch (GeneralSecurityException e) { } try { manager .validateKey( HmacKey.newBuilder(validKey) .setParams(HmacParams.newBuilder(validKey.getParams()).setTagSize(32).build()) .build()); fail(); } catch (GeneralSecurityException e) { } }
@Override public void validateKey(HmacKey key) throws GeneralSecurityException { Validators.validateVersion(key.getVersion(), getVersion()); if (key.getKeyValue().size() < MIN_KEY_SIZE_IN_BYTES) { throw new GeneralSecurityException("key too short"); } validateParams(key.getParams()); }
HmacKeyManager extends KeyTypeManager<HmacKey> { @Override public void validateKey(HmacKey key) throws GeneralSecurityException { Validators.validateVersion(key.getVersion(), getVersion()); if (key.getKeyValue().size() < MIN_KEY_SIZE_IN_BYTES) { throw new GeneralSecurityException("key too short"); } validateParams(key.getParams()); } }
HmacKeyManager extends KeyTypeManager<HmacKey> { @Override public void validateKey(HmacKey key) throws GeneralSecurityException { Validators.validateVersion(key.getVersion(), getVersion()); if (key.getKeyValue().size() < MIN_KEY_SIZE_IN_BYTES) { throw new GeneralSecurityException("key too short"); } validateParams(key.getParams()); } HmacKeyManager(); }
HmacKeyManager extends KeyTypeManager<HmacKey> { @Override public void validateKey(HmacKey key) throws GeneralSecurityException { Validators.validateVersion(key.getVersion(), getVersion()); if (key.getKeyValue().size() < MIN_KEY_SIZE_IN_BYTES) { throw new GeneralSecurityException("key too short"); } validateParams(key.getParams()); } HmacKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override void validateKey(HmacKey key); @Override HmacKey parseKey(ByteString byteString); @Override KeyFactory<HmacKeyFormat, HmacKey> keyFactory(); static void register(boolean newKeyAllowed); static final KeyTemplate hmacSha256HalfDigestTemplate(); static final KeyTemplate hmacSha256Template(); static final KeyTemplate hmacSha512HalfDigestTemplate(); static final KeyTemplate hmacSha512Template(); }
HmacKeyManager extends KeyTypeManager<HmacKey> { @Override public void validateKey(HmacKey key) throws GeneralSecurityException { Validators.validateVersion(key.getVersion(), getVersion()); if (key.getKeyValue().size() < MIN_KEY_SIZE_IN_BYTES) { throw new GeneralSecurityException("key too short"); } validateParams(key.getParams()); } HmacKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override void validateKey(HmacKey key); @Override HmacKey parseKey(ByteString byteString); @Override KeyFactory<HmacKeyFormat, HmacKey> keyFactory(); static void register(boolean newKeyAllowed); static final KeyTemplate hmacSha256HalfDigestTemplate(); static final KeyTemplate hmacSha256Template(); static final KeyTemplate hmacSha512HalfDigestTemplate(); static final KeyTemplate hmacSha512Template();  }