in java/cose/CoseEncrypt.java [67:94]
public static CoseEncrypt decode(byte[] data) throws CborException {
DataItem coseEncrypt = CborUtil.cborToDataItem(data);
Array array = CborUtil.asArray(coseEncrypt);
List<DataItem> dataItems = array.getDataItems();
if (dataItems.size() != COSE_ENCRYPT_LENGTH) {
throw new CborException(
String.format(
"Recipient has the wrong length \nExpected: %s\nActual: %s",
COSE_ENCRYPT_LENGTH, dataItems.size()));
}
byte[] protectedHeaders =
CborUtil.asByteString(dataItems.get(COSE_ENCRYPT_PROTECTED_HEADERS_INDEX)).getBytes();
Map unprotectedHeaders = CborUtil.asMap(dataItems.get(COSE_ENCRYPT_UNPROTECTED_HEADERS_INDEX));
byte[] ciphertext =
CborUtil.asByteString(dataItems.get(COSE_ENCRYPT_CIPHERTEXT_INDEX)).getBytes();
Array recipientArray = CborUtil.asArray(dataItems.get(COSE_ENCRYPT_RECIPIENTS_INDEX));
ImmutableList.Builder<byte[]> builder = ImmutableList.builder();
for (DataItem entry : recipientArray.getDataItems()) {
builder.add(CborUtil.asByteString(entry).getBytes());
}
return new CoseEncrypt(protectedHeaders, unprotectedHeaders, ciphertext, builder.build());
}