17
17
18
18
import com .hierynomus .sshj .transport .mac .Macs ;
19
19
import net .schmizz .sshj .common .SSHRuntimeException ;
20
- import org .bouncycastle . util .encoders . Hex ;
20
+ import org .apache . sshd . common . util .buffer . BufferUtils ;
21
21
import org .junit .jupiter .api .Test ;
22
22
23
23
import java .nio .charset .Charset ;
24
+ import java .nio .charset .StandardCharsets ;
24
25
25
26
import static org .hamcrest .CoreMatchers .is ;
26
27
import static org .hamcrest .MatcherAssert .assertThat ;
27
28
import static org .junit .jupiter .api .Assertions .assertThrows ;
28
29
import static org .junit .jupiter .api .Assertions .fail ;
29
30
30
31
public class BaseMacTest {
31
- private static final Charset CHARSET = Charset . forName ( "US-ASCII" ) ;
32
+ private static final Charset CHARSET = StandardCharsets . US_ASCII ;
32
33
private static final byte [] PLAIN_TEXT = "Hello World" .getBytes (CHARSET );
33
- private static final String EXPECTED_HMAC = "24ddeed57ad91465c5b59dce74ef73778bfb0cb9 " ;
34
+ private static final String EXPECTED_HMAC = "24 dd ee d5 7a d9 14 65 c5 b5 9d ce 74 ef 73 77 8b fb 0c b9 " ;
34
35
private static final String KEY = "et1Quo5ooCie6theel8i" ;
35
36
36
37
@ Test
37
38
public void testResizeTooBigKeys () {
38
39
BaseMAC hmac = Macs .HMACSHA1 ().create ();
39
40
hmac .init ((KEY + "foo" ).getBytes (CHARSET ));
40
41
hmac .update (PLAIN_TEXT );
41
- assertThat (Hex . toHexString (hmac .doFinal ()), is (EXPECTED_HMAC ));
42
+ assertThat (BufferUtils . toHex (hmac .doFinal ()), is (EXPECTED_HMAC ));
42
43
}
43
44
44
45
@ Test
@@ -54,7 +55,7 @@ public void testUnknownAlgorithm() {
54
55
public void testUpdateWithDoFinal () {
55
56
BaseMAC hmac = initHmac ();
56
57
hmac .update (PLAIN_TEXT );
57
- assertThat (Hex . toHexString (hmac .doFinal ()), is (EXPECTED_HMAC ));
58
+ assertThat (BufferUtils . toHex (hmac .doFinal ()), is (EXPECTED_HMAC ));
58
59
}
59
60
60
61
@ Test
@@ -67,13 +68,13 @@ public void testUpdateWithRange() {
67
68
68
69
// update with the range from the second to penultimate byte
69
70
hmac .update (plainText , 1 , PLAIN_TEXT .length );
70
- assertThat (Hex . toHexString (hmac .doFinal ()), is (EXPECTED_HMAC ));
71
+ assertThat (BufferUtils . toHex (hmac .doFinal ()), is (EXPECTED_HMAC ));
71
72
}
72
73
73
74
@ Test
74
75
public void testDoFinalWithInput () {
75
76
BaseMAC hmac = initHmac ();
76
- assertThat (Hex . toHexString (hmac .doFinal (PLAIN_TEXT )), is (EXPECTED_HMAC ));
77
+ assertThat (BufferUtils . toHex (hmac .doFinal (PLAIN_TEXT )), is (EXPECTED_HMAC ));
77
78
}
78
79
79
80
@ Test
@@ -82,7 +83,7 @@ public void testUpdateWithDoFinalWithResultBuffer() {
82
83
byte [] resultBuf = new byte [20 ];
83
84
hmac .update (PLAIN_TEXT );
84
85
hmac .doFinal (resultBuf , 0 );
85
- assertThat (Hex . toHexString (resultBuf ), is (EXPECTED_HMAC ));
86
+ assertThat (BufferUtils . toHex (resultBuf ), is (EXPECTED_HMAC ));
86
87
}
87
88
88
89
private BaseMAC initHmac () {
0 commit comments