use of okio.ByteString in project zipkin by openzipkin.
the class AWSSignatureVersion4 method sign.
Request sign(Request input) throws IOException {
AWSCredentials credentials = checkNotNull(this.credentials.get(), "awsCredentials");
String timestamp = iso8601.get().format(new Date());
String yyyyMMdd = timestamp.substring(0, 8);
String credentialScope = format("%s/%s/%s/%s", yyyyMMdd, region, service, "aws4_request");
Request.Builder builder = input.newBuilder();
builder.header(HOST, input.url().host());
builder.header(X_AMZ_DATE, timestamp);
if (credentials.sessionToken != null) {
builder.header(X_AMZ_SECURITY_TOKEN, credentials.sessionToken);
}
Buffer canonicalString = canonicalString(builder.build());
String signedHeaders = credentials.sessionToken == null ? HOST_DATE : HOST_DATE_TOKEN;
Buffer toSign = toSign(timestamp, credentialScope, canonicalString);
// TODO: this key is invalid when the secret key or the date change. both are very infrequent
ByteString signatureKey = signatureKey(credentials.secretKey, yyyyMMdd);
String signature = toSign.readByteString().hmacSha256(signatureKey).hex();
String authorization = new StringBuilder().append("AWS4-HMAC-SHA256 Credential=").append(credentials.accessKey).append('/').append(credentialScope).append(", SignedHeaders=").append(signedHeaders).append(", Signature=").append(signature).toString();
return builder.header("authorization", authorization).build();
}
use of okio.ByteString in project okhttp by square.
the class WebSocketWriterTest method assertData.
private void assertData(String hex) throws EOFException {
ByteString expected = ByteString.decodeHex(hex);
ByteString actual = data.readByteString(expected.size());
assertEquals(expected, actual);
}
use of okio.ByteString in project retrofit by square.
the class ProtoConverterFactoryTest method deserializeWrongType.
@Test
public void deserializeWrongType() throws IOException {
ByteString encoded = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwOQ==");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
try {
service.wrongType();
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("" + "Unable to create converter for java.util.List<java.lang.String>\n" + " for method Service.wrongType");
assertThat(e.getCause()).hasMessage("" + "Could not locate ResponseBody converter for java.util.List<java.lang.String>.\n" + " Tried:\n" + " * retrofit2.BuiltInConverters\n" + " * retrofit2.converter.protobuf.ProtoConverterFactory");
}
}
use of okio.ByteString in project retrofit by square.
the class ProtoConverterFactoryTest method deserializeUsesRegistry.
@Test
public void deserializeUsesRegistry() throws IOException {
ByteString encoded = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwORAB");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
Call<Phone> call = serviceWithRegistry.get();
Response<Phone> response = call.execute();
Phone body = response.body();
assertThat(body.getNumber()).isEqualTo("(519) 867-5309");
assertThat(body.getExtension(PhoneProtos.voicemail)).isEqualTo(true);
}
use of okio.ByteString in project retrofit by square.
the class ProtoConverterFactoryTest method deserializeWrongValue.
@Test
public void deserializeWrongValue() throws IOException {
ByteString encoded = ByteString.decodeBase64("////");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
Call<?> call = service.get();
try {
call.execute();
fail();
} catch (RuntimeException e) {
assertThat(e.getCause()).isInstanceOf(InvalidProtocolBufferException.class).hasMessageContaining("input ended unexpectedly");
}
}
Aggregations