List of usage examples for com.google.common.io ByteArrayDataOutput write
@Override void write(byte b[]);
From source file:com.yubico.u2f.data.messages.key.CodecTestUtils.java
public static byte[] encodeAuthenticateResponse(RawAuthenticateResponse rawAuthenticateResponse) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(rawAuthenticateResponse.getUserPresence()); encoded.writeInt((int) rawAuthenticateResponse.getCounter()); encoded.write(rawAuthenticateResponse.getSignature()); return encoded.toByteArray(); }
From source file:com.yubico.u2f.data.messages.key.CodecTestUtils.java
public static byte[] encodeRegisterResponse(RawRegisterResponse rawRegisterResponse) throws U2fBadInputException { byte[] keyHandle = rawRegisterResponse.keyHandle; if (keyHandle.length > 255) { throw new U2fBadInputException("keyHandle length cannot be longer than 255 bytes!"); }/*from w w w. jav a2 s .co m*/ try { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(RawRegisterResponse.REGISTRATION_RESERVED_BYTE_VALUE); encoded.write(rawRegisterResponse.userPublicKey); encoded.write((byte) keyHandle.length); encoded.write(keyHandle); encoded.write(rawRegisterResponse.attestationCertificate.getEncoded()); encoded.write(rawRegisterResponse.signature); return encoded.toByteArray(); } catch (CertificateEncodingException e) { throw new U2fBadInputException("Error when encoding attestation certificate.", e); } }
From source file:org.jclouds.crypto.SshKeys.java
public static void encodeUint32(int value, ByteArrayDataOutput out) { out.write((byte) ((value >>> 24) & 0xff)); out.write((byte) ((value >>> 16) & 0xff)); out.write((byte) ((value >>> 8) & 0xff)); out.write((byte) (value & 0xff)); }
From source file:u2f.data.messages.key.RawAuthenticateResponse.java
public static byte[] packBytesToSign(byte[] appIdHash, byte userPresence, long counter, byte[] challengeHash) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(appIdHash); encoded.write(userPresence);//from w w w. ja v a 2 s .c om encoded.writeInt((int) counter); encoded.write(challengeHash); return encoded.toByteArray(); }
From source file:u2f.data.messages.key.RawRegisterResponse.java
public static byte[] packBytesToSign(byte[] appIdHash, byte[] clientDataHash, byte[] keyHandle, byte[] userPublicKey) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(REGISTRATION_SIGNED_RESERVED_BYTE_VALUE); encoded.write(appIdHash);/* w ww. j av a2s . c o m*/ encoded.write(clientDataHash); encoded.write(keyHandle); encoded.write(userPublicKey); return encoded.toByteArray(); }
From source file:org.jclouds.crypto.SshKeys.java
public static String encodeAsOpenSSH(RSAPublicKey key) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); /* encode the "ssh-rsa" string */ out.write(sshrsa); /* Encode the public exponent */ BigInteger e = key.getPublicExponent(); byte[] data = e.toByteArray(); encodeUint32(data.length, out);//from w ww . j a v a 2s .c o m out.write(data); /* Encode the modulus */ BigInteger m = key.getModulus(); data = m.toByteArray(); encodeUint32(data.length, out); out.write(data); return "ssh-rsa " + CryptoStreams.base64(out.toByteArray()); }
From source file:io.opencensus.implcore.tags.propagation.SerializationUtils.java
private static final void encodeTag(Tag tag, ByteArrayDataOutput byteArrayDataOutput) { byteArrayDataOutput.write(TAG_FIELD_ID); encodeString(tag.getKey().getName(), byteArrayDataOutput); encodeString(tag.getValue().asString(), byteArrayDataOutput); }
From source file:com.google.devrel.gmscore.tools.apk.arsc.ResourceString.java
private static void encodeLength(ByteArrayDataOutput output, int length, Type type) { if (length < 0) { output.write(0); return;// w ww . j a va 2s . co m } if (type == Type.UTF8) { if (length > 0x7F) { output.write(((length & 0x7F00) >> 8) | 0x80); } output.write(length & 0xFF); } else { // UTF-16 // TODO(acornwall): Replace output with a little-endian output. if (length > 0x7FFF) { int highBytes = ((length & 0x7FFF0000) >> 16) | 0x8000; output.write(highBytes & 0xFF); output.write((highBytes & 0xFF00) >> 8); } int lowBytes = length & 0xFFFF; output.write(lowBytes & 0xFF); output.write((lowBytes & 0xFF00) >> 8); } }
From source file:io.opencensus.implcore.tags.propagation.SerializationUtils.java
static byte[] serializeBinary(TagContext tags) throws TagContextSerializationException { // Use a ByteArrayDataOutput to avoid needing to handle IOExceptions. final ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput(); byteArrayDataOutput.write(VERSION_ID); int totalChars = 0; // Here chars are equivalent to bytes, since we're using ascii chars. for (Iterator<Tag> i = InternalUtils.getTags(tags); i.hasNext();) { Tag tag = i.next();/*from w w w . j a va 2 s.c o m*/ if (TagTtl.NO_PROPAGATION.equals(tag.getTagMetadata().getTagTtl())) { continue; } totalChars += tag.getKey().getName().length(); totalChars += tag.getValue().asString().length(); encodeTag(tag, byteArrayDataOutput); } if (totalChars > TAGCONTEXT_SERIALIZED_SIZE_LIMIT) { throw new TagContextSerializationException( "Size of TagContext exceeds the maximum serialized size " + TAGCONTEXT_SERIALIZED_SIZE_LIMIT); } return byteArrayDataOutput.toByteArray(); }
From source file:io.opencensus.implcore.tags.propagation.SerializationUtils.java
private static final void encodeString(String input, ByteArrayDataOutput byteArrayDataOutput) { putVarInt(input.length(), byteArrayDataOutput); byteArrayDataOutput.write(input.getBytes(Charsets.UTF_8)); }