@@ -26,18 +26,19 @@ public class EncryptMessageTest {
2626 static byte [] rgbIV96 = {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 };
2727
2828 Recipient recipient128 ;
29- CBORObject cnKey128 ;
29+ OneKey cnKey128 ;
3030
3131 @ Rule
3232 public ExpectedException thrown = ExpectedException .none ();
3333
3434 @ Before
3535 public void setUp () throws CoseException {
3636 recipient128 = new Recipient ();
37- recipient128 .addAttribute (HeaderKeys .Algorithm , AlgorithmID .Direct .AsCBOR (), Attribute .UnprotectedAttributes );
38- cnKey128 = CBORObject .NewMap ();
39- cnKey128 .Add (KeyKeys .KeyType .AsCBOR (), KeyKeys .KeyType_Octet );
40- cnKey128 .Add (KeyKeys .Octet_K .AsCBOR (), CBORObject .FromObject (rgbKey128 ));
37+ recipient128 .addAttribute (HeaderKeys .Algorithm , AlgorithmID .Direct .AsCBOR (), Attribute .UNPROTECTED );
38+ CBORObject key128 = CBORObject .NewMap ();
39+ key128 .Add (KeyKeys .KeyType .AsCBOR (), KeyKeys .KeyType_Octet );
40+ key128 .Add (KeyKeys .Octet_K .AsCBOR (), CBORObject .FromObject (rgbKey128 ));
41+ cnKey128 = new OneKey (key128 );
4142 recipient128 .SetKey (cnKey128 );
4243 }
4344
@@ -48,8 +49,8 @@ public void setUp() throws CoseException {
4849 public void testRoundTrip () throws Exception {
4950 System .out .println ("Round Trip" );
5051 EncryptMessage msg = new EncryptMessage ();
51- msg .AddProtected (HeaderKeys .Algorithm , AlgorithmID .AES_GCM_128 .AsCBOR ());
52- msg .AddProtected (HeaderKeys .IV , CBORObject .FromObject (rgbIV96 ));
52+ msg .addAttribute (HeaderKeys .Algorithm , AlgorithmID .AES_GCM_128 .AsCBOR (), Attribute . PROTECTED );
53+ msg .addAttribute (HeaderKeys .IV , CBORObject .FromObject (rgbIV96 ), Attribute . PROTECTED );
5354 msg .SetContent (rgbContent );
5455 msg .addRecipient (recipient128 );
5556 msg .encrypt ();
@@ -85,7 +86,7 @@ public void encryptNoRecipients() throws CoseException, InvalidCipherTextExcepti
8586
8687 thrown .expect (CoseException .class );
8788 thrown .expectMessage ("No recipients supplied" );
88- msg .AddProtected (HeaderKeys .Algorithm , AlgorithmID .AES_GCM_128 .AsCBOR ());
89+ msg .addAttribute (HeaderKeys .Algorithm , AlgorithmID .AES_GCM_128 .AsCBOR (), Attribute . PROTECTED );
8990 msg .SetContent (rgbContent );
9091 msg .encrypt ();
9192 }
@@ -108,7 +109,7 @@ public void encryptUnknownAlgorithm() throws CoseException, InvalidCipherTextExc
108109
109110 thrown .expect (CoseException .class );
110111 thrown .expectMessage ("Unknown Algorithm Specified" );
111- msg .AddProtected (HeaderKeys .Algorithm , CBORObject .FromObject ("Unknown" ));
112+ msg .addAttribute (HeaderKeys .Algorithm , CBORObject .FromObject ("Unknown" ), Attribute . PROTECTED );
112113 msg .SetContent (rgbContent );
113114 msg .encrypt ();
114115 }
@@ -120,7 +121,7 @@ public void encryptUnsupportedAlgorithm() throws CoseException, InvalidCipherTex
120121
121122 thrown .expect (CoseException .class );
122123 thrown .expectMessage ("Unsupported Algorithm Specified" );
123- msg .AddProtected (HeaderKeys .Algorithm , AlgorithmID .HMAC_SHA_256 .AsCBOR ());
124+ msg .addAttribute (HeaderKeys .Algorithm , AlgorithmID .HMAC_SHA_256 .AsCBOR (), Attribute . PROTECTED );
124125 msg .SetContent (rgbContent );
125126 msg .encrypt ();
126127 }
@@ -132,7 +133,7 @@ public void encryptNoContent() throws CoseException, InvalidCipherTextException,
132133
133134 thrown .expect (CoseException .class );
134135 thrown .expectMessage ("No Content Specified" );
135- msg .AddProtected (HeaderKeys .Algorithm , AlgorithmID .AES_GCM_128 .AsCBOR ());
136+ msg .addAttribute (HeaderKeys .Algorithm , AlgorithmID .AES_GCM_128 .AsCBOR (), Attribute . PROTECTED );
136137 msg .encrypt ();
137138 }
138139
@@ -143,8 +144,8 @@ public void encryptBadIV() throws CoseException, InvalidCipherTextException, Exc
143144
144145 thrown .expect (CoseException .class );
145146 thrown .expectMessage ("IV is incorrectly formed" );
146- msg .AddProtected (HeaderKeys .Algorithm , AlgorithmID .AES_GCM_128 .AsCBOR ());
147- msg .AddUnprotected (HeaderKeys .IV , CBORObject .FromObject ("IV" ));
147+ msg .addAttribute (HeaderKeys .Algorithm , AlgorithmID .AES_GCM_128 .AsCBOR (), Attribute . PROTECTED );
148+ msg .addAttribute (HeaderKeys .IV , CBORObject .FromObject ("IV" ), Attribute . UNPROTECTED );
148149 msg .SetContent (rgbContent );
149150 msg .encrypt ();
150151 }
@@ -156,8 +157,8 @@ public void encryptIncorrectIV() throws CoseException, InvalidCipherTextExceptio
156157
157158 thrown .expect (CoseException .class );
158159 thrown .expectMessage ("IV size is incorrect" );
159- msg .AddProtected (HeaderKeys .Algorithm , AlgorithmID .AES_GCM_128 .AsCBOR ());
160- msg .AddUnprotected (HeaderKeys .IV , rgbIV128 );
160+ msg .addAttribute (HeaderKeys .Algorithm , AlgorithmID .AES_GCM_128 .AsCBOR (), Attribute . PROTECTED );
161+ msg .addAttribute (HeaderKeys .IV , rgbIV128 , Attribute . UNPROTECTED );
161162 msg .SetContent (rgbContent );
162163 msg .encrypt ();
163164 }
0 commit comments