@Test void convert_too_short_data_test() { byte[] input = Base64UrlUtil.decode("SZYN5YgOjGh0NBcP"); AuthenticatorDataConverter authenticatorDataConverter = new AuthenticatorDataConverter(objectConverter); assertThrows(DataConversionException.class, () -> authenticatorDataConverter.convert(input) ); }
public <T extends ExtensionAuthenticatorOutput> byte[] convert(AuthenticatorData<T> source) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] rpIdHash = source.getRpIdHash(); byteArrayOutputStream.write(rpIdHash); byteArrayOutputStream.write(new byte[]{source.getFlags()}); byteArrayOutputStream.write(UnsignedNumberUtil.toBytes(source.getSignCount())); if (source.getAttestedCredentialData() != null) { byteArrayOutputStream.write(attestedCredentialDataConverter.convert(source.getAttestedCredentialData())); } byteArrayOutputStream.write(convert(source.getExtensions())); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } }
AuthenticatorDataConverter { public <T extends ExtensionAuthenticatorOutput> byte[] convert(AuthenticatorData<T> source) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] rpIdHash = source.getRpIdHash(); byteArrayOutputStream.write(rpIdHash); byteArrayOutputStream.write(new byte[]{source.getFlags()}); byteArrayOutputStream.write(UnsignedNumberUtil.toBytes(source.getSignCount())); if (source.getAttestedCredentialData() != null) { byteArrayOutputStream.write(attestedCredentialDataConverter.convert(source.getAttestedCredentialData())); } byteArrayOutputStream.write(convert(source.getExtensions())); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } } }
AuthenticatorDataConverter { public <T extends ExtensionAuthenticatorOutput> byte[] convert(AuthenticatorData<T> source) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] rpIdHash = source.getRpIdHash(); byteArrayOutputStream.write(rpIdHash); byteArrayOutputStream.write(new byte[]{source.getFlags()}); byteArrayOutputStream.write(UnsignedNumberUtil.toBytes(source.getSignCount())); if (source.getAttestedCredentialData() != null) { byteArrayOutputStream.write(attestedCredentialDataConverter.convert(source.getAttestedCredentialData())); } byteArrayOutputStream.write(convert(source.getExtensions())); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } } AuthenticatorDataConverter(ObjectConverter objectConverter); }
AuthenticatorDataConverter { public <T extends ExtensionAuthenticatorOutput> byte[] convert(AuthenticatorData<T> source) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] rpIdHash = source.getRpIdHash(); byteArrayOutputStream.write(rpIdHash); byteArrayOutputStream.write(new byte[]{source.getFlags()}); byteArrayOutputStream.write(UnsignedNumberUtil.toBytes(source.getSignCount())); if (source.getAttestedCredentialData() != null) { byteArrayOutputStream.write(attestedCredentialDataConverter.convert(source.getAttestedCredentialData())); } byteArrayOutputStream.write(convert(source.getExtensions())); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } } AuthenticatorDataConverter(ObjectConverter objectConverter); byte[] convert(AuthenticatorData<T> source); AuthenticatorData<T> convert(byte[] source); byte[] extractAttestedCredentialData(byte[] authenticatorData); long extractSignCount(byte[] authenticatorData); }
AuthenticatorDataConverter { public <T extends ExtensionAuthenticatorOutput> byte[] convert(AuthenticatorData<T> source) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] rpIdHash = source.getRpIdHash(); byteArrayOutputStream.write(rpIdHash); byteArrayOutputStream.write(new byte[]{source.getFlags()}); byteArrayOutputStream.write(UnsignedNumberUtil.toBytes(source.getSignCount())); if (source.getAttestedCredentialData() != null) { byteArrayOutputStream.write(attestedCredentialDataConverter.convert(source.getAttestedCredentialData())); } byteArrayOutputStream.write(convert(source.getExtensions())); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } } AuthenticatorDataConverter(ObjectConverter objectConverter); byte[] convert(AuthenticatorData<T> source); AuthenticatorData<T> convert(byte[] source); byte[] extractAttestedCredentialData(byte[] authenticatorData); long extractSignCount(byte[] authenticatorData);  }