alts: Use Guava base16 decoding functions in tests

The previously used javax.xml.bind.DatatypeConverter is deprecated in
Java 9.
This commit is contained in:
Benedikt Schmidt 2018-03-16 16:01:04 -07:00 committed by Carl Mastrangelo
parent 2ce1d370a0
commit fd96cc2ddf
2 changed files with 8 additions and 7 deletions

View File

@ -22,7 +22,8 @@ dependencies {
project(':grpc-stub'), project(':grpc-stub'),
libraries.lang, libraries.lang,
libraries.protobuf libraries.protobuf
testCompile libraries.guava_testlib, testCompile libraries.guava,
libraries.guava_testlib,
libraries.junit, libraries.junit,
libraries.mockito, libraries.mockito,
libraries.truth libraries.truth

View File

@ -18,10 +18,10 @@ package io.grpc.alts.internal;
import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage;
import com.google.common.io.BaseEncoding;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.Arrays; import java.util.Arrays;
import javax.xml.bind.DatatypeConverter;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -78,27 +78,27 @@ public final class AesGcmHkdfAeadCrypterTest {
} }
TestVectorBuilder withKey(String key) { TestVectorBuilder withKey(String key) {
this.key = DatatypeConverter.parseHexBinary(key); this.key = BaseEncoding.base16().lowerCase().decode(key);
return this; return this;
} }
TestVectorBuilder withNonce(String nonce) { TestVectorBuilder withNonce(String nonce) {
this.nonce = DatatypeConverter.parseHexBinary(nonce); this.nonce = BaseEncoding.base16().lowerCase().decode(nonce);
return this; return this;
} }
TestVectorBuilder withAad(String aad) { TestVectorBuilder withAad(String aad) {
this.aad = DatatypeConverter.parseHexBinary(aad); this.aad = BaseEncoding.base16().lowerCase().decode(aad);
return this; return this;
} }
TestVectorBuilder withPlaintext(String plaintext) { TestVectorBuilder withPlaintext(String plaintext) {
this.plaintext = DatatypeConverter.parseHexBinary(plaintext); this.plaintext = BaseEncoding.base16().lowerCase().decode(plaintext);
return this; return this;
} }
TestVectorBuilder withCiphertext(String ciphertext) { TestVectorBuilder withCiphertext(String ciphertext) {
this.ciphertext = DatatypeConverter.parseHexBinary(ciphertext); this.ciphertext = BaseEncoding.base16().lowerCase().decode(ciphertext);
return this; return this;
} }
} }