<commit_before>package cms

import (
	"crypto/x509/pkix"
	"encoding/asn1"
	"math/big"
	"time"
)

// -- Imports from RFC 5280 [PROFILE], Appendix A.1
//       AlgorithmIdentifier, Certificate, CertificateList,
//       CertificateSerialNumber, Name
//          FROM PKIX1Explicit88
//               { iso(1) identified-organization(3) dod(6)
//                 internet(1) security(5) mechanisms(5) pkix(7)
//                 mod(0) pkix1-explicit(18) }

// -- Imports from RFC 3281 [ACPROFILE], Appendix B
//       AttributeCertificate
//          FROM PKIXAttributeCertificate
//               { iso(1) identified-organization(3) dod(6)
//                 internet(1) security(5) mechanisms(5) pkix(7)
//                 mod(0) attribute-cert(12) }

// -- Imports from Appendix B of this document
//       AttributeCertificateV1
//          FROM AttributeCertificateVersion1
//               { iso(1) member-body(2) us(840) rsadsi(113549)
//                 pkcs(1) pkcs-9(9) smime(16) modules(0)
//                 v1AttrCert(15) }

// -- Cryptographic Message Syntax

// ContentInfo ::= SEQUENCE {
//   contentType ContentType,
//   content [0] EXPLICIT ANY DEFINED BY contentType }
// ContentType ::= OBJECT IDENTIFIER
type ContentInfo struct {
	ContentType asn1.ObjectIdentifier
	Content     interface{} `asn1:"tag:0,explicit"`
}

// SignedData ::= SEQUENCE {
//   version CMSVersion,
//   digestAlgorithms DigestAlgorithmIdentifiers,
//   encapContentInfo EncapsulatedContentInfo,
//   certificates [0] IMPLICIT CertificateSet OPTIONAL,
//   crls [1] IMPLICIT RevocationInfoChoices OPTIONAL,
//   signerInfos SignerInfos }

// DigestAlgorithmIdentifiersSET ::= SET OF DigestAlgorithmIdentifier
type DigestAlgorithmIdentifiersSET []pkix.AlgorithmIdentifier

// SignerInfos ::= SET OF SignerInfo

// EncapsulatedContentInfo ::= SEQUENCE {
//   eContentType ContentType,
//   eContent [0] EXPLICIT OCTET STRING OPTIONAL }
type EncapsulatedContentInfo struct {
	EContentType asn1.ObjectIdentifier
	EContent     []byte `asn1:"tag:0,explicit,optional,omitempty"`
}

// SignerInfo ::= SEQUENCE {
//   version CMSVersion,
//   sid SignerIdentifier ::= CHOICE {
//     issuerAndSerialNumber IssuerAndSerialNumber,
//     subjectKeyIdentifier [0] SubjectKeyIdentifier }
//   digestAlgorithm DigestAlgorithmIdentifier,
//   signedAttrs [0] IMPLICIT SignedAttributes OPTIONAL,
//   signatureAlgorithm SignatureAlgorithmIdentifier,
//   signature SignatureValue,
//   unsignedAttrs [1] IMPLICIT UnsignedAttributes OPTIONAL }
type SignerInfo struct {
	Version                   CMSVersion
	IssuerAndSerialNumber     IssuerAndSerialNumber `asn1:"optional"`
	SubjectKeyIdentifier      SubjectKeyIdentifier  `asn1:"tag:0,implicit,optional"`
	DigestAlgorithmIdentifier pkix.AlgorithmIdentifier
	SignedAttrs               SignedAttributesSET `asn1:"tag:0,implicit,optional"`
	SignatureAlgorithm        pkix.AlgorithmIdentifier
	Signature                 SignatureValue
	UnsignedAttributes        UnsignedAttributesSET `asn1:"tag:1,implicit,optional"`
}

// SignedAttributesSET ::= SET SIZE (1..MAX) OF Attribute
type SignedAttributesSET []Attribute

// UnsignedAttributesSET ::= SET SIZE (1..MAX) OF Attribute
type UnsignedAttributesSET []Attribute

// Attribute ::= SEQUENCE {
//   attrType OBJECT IDENTIFIER,
//   attrValues SET OF AttributeValue }
type Attribute struct {
	AttrType   asn1.ObjectIdentifier
	AttrValues []AttributeValue `asn1:"set"`
}

// AttributeValue ::= ANY
type AttributeValue interface{}

// SignatureValue ::= OCTET STRING
type SignatureValue []byte

// EnvelopedData ::= SEQUENCE {
//   version CMSVersion,
//   originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
//   recipientInfos RecipientInfos,
//   encryptedContentInfo EncryptedContentInfo,
//   unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL }

// OriginatorInfo ::= SEQUENCE {
//   certs [0] IMPLICIT CertificateSet OPTIONAL,
//   crls [1] IMPLICIT RevocationInfoChoices OPTIONAL }

// RecipientInfos ::= SET SIZE (1..MAX) OF RecipientInfo

// EncryptedContentInfo ::= SEQUENCE {
//   contentType ContentType,
//   contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
//   encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL }
type EncryptedContentInfo struct {
	ContentType                asn1.ObjectIdentifier
	ContentEncryptionAlgorithm pkix.AlgorithmIdentifier
	EncryptedContent           EncryptedContent `asn1:"implicit,tag:0,optional"`
}

// EncryptedContent ::= OCTET STRING
type EncryptedContent []byte

// UnprotectedAttributesSET ::= SET SIZE (1..MAX) OF Attribute
type UnprotectedAttributesSET []Attribute

// RecipientInfo ::= CHOICE {
//   ktri KeyTransRecipientInfo,
//   kari [1] KeyAgreeRecipientInfo,
//   kekri [2] KEKRecipientInfo,
//   pwri [3] PasswordRecipientInfo,
//   ori [4] OtherRecipientInfo }

// EncryptedKey ::= OCTET STRING
type EncryptedKey []byte

// KeyTransRecipientInfo ::= SEQUENCE {
//   version CMSVersion,  -- always set to 0 or 2
//   rid RecipientIdentifier,
//   keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
//   encryptedKey EncryptedKey }

// RecipientIdentifier ::= CHOICE {
//   issuerAndSerialNumber IssuerAndSerialNumber,
//   subjectKeyIdentifier [0] SubjectKeyIdentifier }

// KeyAgreeRecipientInfo ::= SEQUENCE {
//   version CMSVersion,  -- always set to 3
//   originator [0] EXPLICIT OriginatorIdentifierOrKey,
//   ukm [1] EXPLICIT UserKeyingMaterial OPTIONAL,
//   keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
//   recipientEncryptedKeys RecipientEncryptedKeys }

// OriginatorIdentifierOrKey ::= CHOICE {
//   issuerAndSerialNumber IssuerAndSerialNumber,
//   subjectKeyIdentifier [0] SubjectKeyIdentifier,
//   originatorKey [1] OriginatorPublicKey }

// OriginatorPublicKey ::= SEQUENCE {
//   algorithm AlgorithmIdentifier,
//   publicKey BIT STRING }
type OriginatorPublicKey struct {
	Algorithm pkix.AlgorithmIdentifier
	PublicKey asn1.BitString
}

// RecipientEncryptedKeys ::= SEQUENCE OF RecipientEncryptedKey
type RecipientEncryptedKeys []RecipientEncryptedKey

// RecipientEncryptedKey ::= SEQUENCE {
//   rid KeyAgreeRecipientIdentifier,
//   encryptedKey EncryptedKey }
type RecipientEncryptedKey struct {
	IssuerAndSerialNumber IssuerAndSerialNumber  `asn1:"optional"`
	RKeyID                RecipientKeyIdentifier `asn1:"implicit,tag:0,optional"`
	EncryptedKey          EncryptedKey
}

// KeyAgreeRecipientIdentifier ::= CHOICE {
//   issuerAndSerialNumber IssuerAndSerialNumber,
//   rKeyId [0] IMPLICIT RecipientKeyIdentifier }

// RecipientKeyIdentifier ::= SEQUENCE {
//   subjectKeyIdentifier SubjectKeyIdentifier,
//   date GeneralizedTime OPTIONAL,
//   other OtherKeyAttribute OPTIONAL }
type RecipientKeyIdentifier struct {
	SubjectKeyIdentifier SubjectKeyIdentifier
	Date                 time.Time
	Other                OtherKeyAttribute `asn1:"optional"`
}

// SubjectKeyIdentifier ::= OCTET STRING
type SubjectKeyIdentifier []byte

// KEKRecipientInfo ::= SEQUENCE {
//   version CMSVersion,  -- always set to 4
//   kekid KEKIdentifier,
//   keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
//   encryptedKey EncryptedKey }

// KEKIdentifier ::= SEQUENCE {
//   keyIdentifier OCTET STRING,<commit_msg>Updated RecipientEncryptedKey comment to reflect implementation of rid CHOICE<commit_after>package cms

import (
	"crypto/x509/pkix"
	"encoding/asn1"
	"math/big"
	"time"
)

// -- Imports from RFC 5280 [PROFILE], Appendix A.1
//       AlgorithmIdentifier, Certificate, CertificateList,
//       CertificateSerialNumber, Name
//          FROM PKIX1Explicit88
//               { iso(1) identified-organization(3) dod(6)
//                 internet(1) security(5) mechanisms(5) pkix(7)
//                 mod(0) pkix1-explicit(18) }

// -- Imports from RFC 3281 [ACPROFILE], Appendix B
//       AttributeCertificate
//          FROM PKIXAttributeCertificate
//               { iso(1) identified-organization(3) dod(6)
//                 internet(1) security(5) mechanisms(5) pkix(7)
//                 mod(0) attribute-cert(12) }

// -- Imports from Appendix B of this document
//       AttributeCertificateV1
//          FROM AttributeCertificateVersion1
//               { iso(1) member-body(2) us(840) rsadsi(113549)
//                 pkcs(1) pkcs-9(9) smime(16) modules(0)
//                 v1AttrCert(15) }

// -- Cryptographic Message Syntax

// ContentInfo ::= SEQUENCE {
//   contentType ContentType,
//   content [0] EXPLICIT ANY DEFINED BY contentType }
// ContentType ::= OBJECT IDENTIFIER
type ContentInfo struct {
	ContentType asn1.ObjectIdentifier
	Content     interface{} `asn1:"tag:0,explicit"`
}

// SignedData ::= SEQUENCE {
//   version CMSVersion,
//   digestAlgorithms DigestAlgorithmIdentifiers,
//   encapContentInfo EncapsulatedContentInfo,
//   certificates [0] IMPLICIT CertificateSet OPTIONAL,
//   crls [1] IMPLICIT RevocationInfoChoices OPTIONAL,
//   signerInfos SignerInfos }

// DigestAlgorithmIdentifiersSET ::= SET OF DigestAlgorithmIdentifier
type DigestAlgorithmIdentifiersSET []pkix.AlgorithmIdentifier

// SignerInfos ::= SET OF SignerInfo

// EncapsulatedContentInfo ::= SEQUENCE {
//   eContentType ContentType,
//   eContent [0] EXPLICIT OCTET STRING OPTIONAL }
type EncapsulatedContentInfo struct {
	EContentType asn1.ObjectIdentifier
	EContent     []byte `asn1:"tag:0,explicit,optional,omitempty"`
}

// SignerInfo ::= SEQUENCE {
//   version CMSVersion,
//   sid SignerIdentifier ::= CHOICE {
//     issuerAndSerialNumber IssuerAndSerialNumber,
//     subjectKeyIdentifier [0] SubjectKeyIdentifier }
//   digestAlgorithm DigestAlgorithmIdentifier,
//   signedAttrs [0] IMPLICIT SignedAttributes OPTIONAL,
//   signatureAlgorithm SignatureAlgorithmIdentifier,
//   signature SignatureValue,
//   unsignedAttrs [1] IMPLICIT UnsignedAttributes OPTIONAL }
type SignerInfo struct {
	Version                   CMSVersion
	IssuerAndSerialNumber     IssuerAndSerialNumber `asn1:"optional"`
	SubjectKeyIdentifier      SubjectKeyIdentifier  `asn1:"tag:0,implicit,optional"`
	DigestAlgorithmIdentifier pkix.AlgorithmIdentifier
	SignedAttrs               SignedAttributesSET `asn1:"tag:0,implicit,optional"`
	SignatureAlgorithm        pkix.AlgorithmIdentifier
	Signature                 SignatureValue
	UnsignedAttributes        UnsignedAttributesSET `asn1:"tag:1,implicit,optional"`
}

// SignedAttributesSET ::= SET SIZE (1..MAX) OF Attribute
type SignedAttributesSET []Attribute

// UnsignedAttributesSET ::= SET SIZE (1..MAX) OF Attribute
type UnsignedAttributesSET []Attribute

// Attribute ::= SEQUENCE {
//   attrType OBJECT IDENTIFIER,
//   attrValues SET OF AttributeValue }
type Attribute struct {
	AttrType   asn1.ObjectIdentifier
	AttrValues []AttributeValue `asn1:"set"`
}

// AttributeValue ::= ANY
type AttributeValue interface{}

// SignatureValue ::= OCTET STRING
type SignatureValue []byte

// EnvelopedData ::= SEQUENCE {
//   version CMSVersion,
//   originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
//   recipientInfos RecipientInfos,
//   encryptedContentInfo EncryptedContentInfo,
//   unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL }

// OriginatorInfo ::= SEQUENCE {
//   certs [0] IMPLICIT CertificateSet OPTIONAL,
//   crls [1] IMPLICIT RevocationInfoChoices OPTIONAL }

// RecipientInfos ::= SET SIZE (1..MAX) OF RecipientInfo

// EncryptedContentInfo ::= SEQUENCE {
//   contentType ContentType,
//   contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
//   encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL }
type EncryptedContentInfo struct {
	ContentType                asn1.ObjectIdentifier
	ContentEncryptionAlgorithm pkix.AlgorithmIdentifier
	EncryptedContent           EncryptedContent `asn1:"implicit,tag:0,optional"`
}

// EncryptedContent ::= OCTET STRING
type EncryptedContent []byte

// UnprotectedAttributesSET ::= SET SIZE (1..MAX) OF Attribute
type UnprotectedAttributesSET []Attribute

// RecipientInfo ::= CHOICE {
//   ktri KeyTransRecipientInfo,
//   kari [1] KeyAgreeRecipientInfo,
//   kekri [2] KEKRecipientInfo,
//   pwri [3] PasswordRecipientInfo,
//   ori [4] OtherRecipientInfo }

// EncryptedKey ::= OCTET STRING
type EncryptedKey []byte

// KeyTransRecipientInfo ::= SEQUENCE {
//   version CMSVersion,  -- always set to 0 or 2
//   rid RecipientIdentifier,
//   keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
//   encryptedKey EncryptedKey }

// RecipientIdentifier ::= CHOICE {
//   issuerAndSerialNumber IssuerAndSerialNumber,
//   subjectKeyIdentifier [0] SubjectKeyIdentifier }

// KeyAgreeRecipientInfo ::= SEQUENCE {
//   version CMSVersion,  -- always set to 3
//   originator [0] EXPLICIT OriginatorIdentifierOrKey,
//   ukm [1] EXPLICIT UserKeyingMaterial OPTIONAL,
//   keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
//   recipientEncryptedKeys RecipientEncryptedKeys }

// OriginatorIdentifierOrKey ::= CHOICE {
//   issuerAndSerialNumber IssuerAndSerialNumber,
//   subjectKeyIdentifier [0] SubjectKeyIdentifier,
//   originatorKey [1] OriginatorPublicKey }

// OriginatorPublicKey ::= SEQUENCE {
//   algorithm AlgorithmIdentifier,
//   publicKey BIT STRING }
type OriginatorPublicKey struct {
	Algorithm pkix.AlgorithmIdentifier
	PublicKey asn1.BitString
}

// RecipientEncryptedKeys ::= SEQUENCE OF RecipientEncryptedKey
type RecipientEncryptedKeys []RecipientEncryptedKey

// RecipientEncryptedKey ::= SEQUENCE {
//   rid ::= CHOICE {
//     issuerAndSerialNumber IssuerAndSerialNumber,
//     rKeyId [0] IMPLICIT RecipientKeyIdentifier }
//   encryptedKey EncryptedKey }
type RecipientEncryptedKey struct {
	IssuerAndSerialNumber IssuerAndSerialNumber  `asn1:"optional"`
	RKeyID                RecipientKeyIdentifier `asn1:"implicit,tag:0,optional"`
	EncryptedKey          EncryptedKey
}

// RecipientKeyIdentifier ::= SEQUENCE {
//   subjectKeyIdentifier SubjectKeyIdentifier,
//   date GeneralizedTime OPTIONAL,
//   other OtherKeyAttribute OPTIONAL }
type RecipientKeyIdentifier struct {
	SubjectKeyIdentifier SubjectKeyIdentifier
	Date                 time.Time
	Other                OtherKeyAttribute `asn1:"optional"`
}

// SubjectKeyIdentifier ::= OCTET STRING
type SubjectKeyIdentifier []byte

// KEKRecipientInfo ::= SEQUENCE {
//   version CMSVersion,  -- always set to 4
//   kekid KEKIdentifier,
//   keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
//   encryptedKey EncryptedKey }

// KEKIdentifier ::= SEQUENCE {
//   keyIdentifier OCTET STRING,
{'fraction_non_alphanumeric': 0.09818030858645264, 'fraction_numerical': 0.015498512419566872, 'mean_word_length': 3.7312602291325696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '441856', 'n_tokens_mistral': 4470, 'n_tokens_neox': 4284, 'n_words': 961}