1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.kerberos.shared.messages.value;
21
22
23 import java.nio.ByteBuffer;
24 import java.util.Arrays;
25
26 import org.apache.directory.server.kerberos.shared.crypto.checksum.ChecksumType;
27
28 import junit.framework.TestCase;
29
30
31
32
33
34
35
36
37 public class ChecksumTest extends TestCase
38 {
39 public void testEncodingChecksum() throws Exception
40 {
41 Checksum chk = new Checksum( ChecksumType.CRC32, new byte[]
42 { 0x01, 0x02, 0x03 } );
43
44 ByteBuffer encoded = ByteBuffer.allocate( chk.computeLength() );
45
46 chk.encode( encoded );
47
48 byte[] expectedResult = new byte[]
49 {
50 0x30, 0x0c,
51 (byte)0xA0, 0x03,
52 0x02, 0x01, 0x01,
53 (byte)0xA1, 0x05,
54 0x04, 0x03,
55 0x01, 0x02, 0x03
56 };
57
58 assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
59 }
60
61
62 public void testEncodingNullChecksum() throws Exception
63 {
64 Checksum chk = new Checksum( ChecksumType.CRC32, null );
65
66 ByteBuffer encoded = ByteBuffer.allocate( chk.computeLength() );
67
68 chk.encode( encoded );
69
70 byte[] expectedResult = new byte[]
71 {
72 0x30, 0x09,
73 ( byte ) 0xA0,
74 0x03, 0x02, 0x01, 0x01,
75 ( byte ) 0xA1, 0x02,
76 0x04, 0x00
77 };
78
79 assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
80 }
81
82
83
84
85
86 public void testEquality()
87 {
88 byte[] checksumValue =
89 { ( byte ) 0x30, ( byte ) 0x1A, ( byte ) 0xA0, ( byte ) 0x11, ( byte ) 0x18, ( byte ) 0x0F, ( byte ) 0x32,
90 ( byte ) 0x30 };
91
92 Checksum expected = new Checksum( ChecksumType.RSA_MD5, checksumValue );
93 Checksum provided = new Checksum( ChecksumType.RSA_MD5, checksumValue );
94
95 assertTrue( "Checksum equality", expected.equals( provided ) );
96 }
97 }