Commits

Anonymous committed e33b1e9 Draft

calculating versions for SignedData, SignerInfo, EnvelopedData

  • Participants
  • Parent commits 16df39c

Comments (0)

Files changed (1)

File asn1/cms.ceylon

 
 class SignedData(digestAlgorithms, encapContentInfo, signerInfos)
         extends ContentInfo(signedDataContentType) {
-    shared Integer version => nothing; // TODO
     shared Set<AlgorithmIdentifier> digestAlgorithms;
     shared EncapsulatedContentInfo encapContentInfo;
     shared Set<SignerInfo> signerInfos;
     
+    // calculated as per http://tools.ietf.org/html/rfc5652#section-5.1
+    shared Integer version {
+        if (signerInfos.any((SignerInfo e) => e.version == 3) ||
+                encapContentInfo.contentInfo.contentType != dataContentType) {
+            return 3;
+        } else {
+            return 1;
+        }
+    }
+    
     shared actual ASN1Sequence content => ASN1Sequence([
         ASN1Integer(wholeNumber(version)),
         ASN1Set(LazySet(digestAlgorithms.map((AlgorithmIdentifier elem) => elem.asn1))),
 class SignerInfo(signerIdentifier, digestAlgorithm, signedAttrs,
         signatureAlgorithm, signature)
         satisfies ASN1Representable {
-    shared Integer version => nothing; // TODO
     shared SignerIdentifier signerIdentifier;
     shared AlgorithmIdentifier digestAlgorithm;
     shared Set<Attribute> signedAttrs;
     
     assert(signedAttrs.size > 0);
     
+    // calculated as per http://tools.ietf.org/html/rfc5652#section-5.3
+    shared Integer version {
+        switch (signerIdentifier)
+        case (is SubjectKeyIdentifier) {
+            return 3;
+        }
+    }
+    
     shared actual ASN1Sequence asn1 => ASN1Sequence([
         ASN1Integer(wholeNumber(version)),
         signerIdentifier.asn1,
 
 class EnvelopedData(recipientInfos, encryptedContentInfo)
         extends ContentInfo(envelopedDataContentType) {
-    shared Integer version => nothing;
     shared Set<RecipientInfo> recipientInfos;
     shared EncryptedContentInfo encryptedContentInfo;
     
     assert(recipientInfos.size > 0);
     
+    // calculated as per http://tools.ietf.org/html/rfc5652#section-6.1
+    shared Integer version {
+        if (recipientInfos.every((RecipientInfo e) => e.version == 0)) {
+            return 0;
+        } else {
+            return 2;
+        }
+    }
+    
     shared actual ASN1Sequence content => ASN1Sequence([
         ASN1Integer(wholeNumber(version)),
         ASN1Set(LazySet(recipientInfos.map((RecipientInfo elem) => elem.asn1))),
 
 abstract class RecipientInfo()
         of KEKRecipientInfo
-        satisfies ASN1Representable {}
+        satisfies ASN1Representable {
+    shared formal Integer version;
+}
 
 class KEKRecipientInfo(kekIdentifier, keyEncryptionAlgorithm, encryptedKey)
         extends RecipientInfo() {
-    shared Integer version = 4;
+    shared actual Integer version = 4;
     shared KEKIdentifier kekIdentifier;
     shared AlgorithmIdentifier keyEncryptionAlgorithm;
     shared OctetString encryptedKey;