@Before public void setUp() throws CoseException { recipient128 = new Recipient(); recipient128.addAttribute( HeaderKeys.Algorithm, AlgorithmID.Direct.AsCBOR(), Attribute.UNPROTECTED); CBORObject key128 = CBORObject.NewMap(); key128.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_Octet); key128.Add(KeyKeys.Octet_K.AsCBOR(), CBORObject.FromObject(rgbKey128)); cnKey128 = new OneKey(key128); recipient128.SetKey(cnKey128); }
protected CBORObject EncodeCBORObject() throws CoseException { if (rgbTag == null) throw new CoseException("Compute function not called"); CBORObject obj = CBORObject.NewArray(); if (objProtected.size() > 0) obj.Add(objProtected.EncodeToBytes()); else obj.Add(CBORObject.FromObject(new byte[0])); obj.Add(objUnprotected); obj.Add(rgbContent); obj.Add(rgbTag); return obj; }
@Test public void encryptDecodeBadRecipients() throws CoseException { CBORObject obj = CBORObject.NewArray(); obj.Add(CBORObject.FromObject(CBORObject.NewArray()).EncodeToBytes()); obj.Add(CBORObject.NewMap()); obj.Add(new byte[0]); obj.Add(CBORObject.False); thrown.expect(CoseException.class); thrown.expectMessage("Invalid Encrypt structure"); byte[] rgb = obj.EncodeToBytes(); Message msg = Message.DecodeFromBytes(rgb, MessageTag.Encrypt); }