github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/smime/encryptionalgorithm.go (about)

     1  package smime
     2  
     3  import "encoding/asn1"
     4  
     5  type EncryptionAlgorithm int
     6  
     7  const (
     8  	UnknownEncryptionAlgorithm EncryptionAlgorithm = iota
     9  	RSA
    10  	RC2_CBC
    11  	RC4
    12  	DES_EDE3_CBC
    13  	RC5_CBC_Pad
    14  	ID_DES_CDMF
    15  )
    16  
    17  func getEncryptionAlgorithmFromOID(oid asn1.ObjectIdentifier) EncryptionAlgorithm {
    18  	for _, details := range encryptionAlgorithmDetails {
    19  		if oid.Equal(details.oid) {
    20  			return details.algo
    21  		}
    22  	}
    23  	return UnknownEncryptionAlgorithm
    24  }
    25  
    26  var (
    27  	oidEncryptionRSA          = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 1}
    28  	oidEncryptionRC2_CBC      = asn1.ObjectIdentifier{1, 2, 840, 113549, 3, 2}
    29  	oidEncryptionRC4          = asn1.ObjectIdentifier{1, 2, 840, 113549, 3, 4}
    30  	oidEncryptionDES_EDE3_CBC = asn1.ObjectIdentifier{1, 2, 840, 113549, 3, 7}
    31  	oidEncryptionRC5_CBC_Pad  = asn1.ObjectIdentifier{1, 2, 840, 113549, 3, 9}
    32  	oidEncryptionID_DES_CDMF  = asn1.ObjectIdentifier{1, 2, 840, 113549, 3, 10}
    33  )
    34  
    35  var encryptionAlgorithmDetails = []struct {
    36  	algo EncryptionAlgorithm
    37  	oid  asn1.ObjectIdentifier
    38  }{
    39  	{RSA, oidEncryptionRSA},
    40  	{RC2_CBC, oidEncryptionRC2_CBC},
    41  	{RC4, oidEncryptionRC4},
    42  	{DES_EDE3_CBC, oidEncryptionDES_EDE3_CBC},
    43  	{RC5_CBC_Pad, oidEncryptionRC5_CBC_Pad},
    44  	{ID_DES_CDMF, oidEncryptionID_DES_CDMF},
    45  }