encryptIdentifier returns a saml:EncryptedID holding identifier, a saml:NameID or saml:BaseID element, encrypted to cert with encrypter. identifier is not modified.
(identifier *etree.Element, cert *x509.Certificate, encrypter xmlenc.Encrypter)
| 94 | // saml:NameID or saml:BaseID element, encrypted to cert with encrypter. |
| 95 | // identifier is not modified. |
| 96 | func encryptIdentifier(identifier *etree.Element, cert *x509.Certificate, encrypter xmlenc.Encrypter) (*etree.Element, error) { |
| 97 | // The plaintext is parsed on its own, so it must declare the namespace |
| 98 | // of its prefix. |
| 99 | identifier = identifier.Copy() |
| 100 | if identifier.Space != "" && identifier.SelectAttr("xmlns:"+identifier.Space) == nil { |
| 101 | identifier.CreateAttr("xmlns:"+identifier.Space, samlAssertionNamespace) |
| 102 | } |
| 103 | doc := etree.NewDocument() |
| 104 | doc.SetRoot(identifier) |
| 105 | plaintext, err := doc.WriteToBytes() |
| 106 | if err != nil { |
| 107 | return nil, err |
| 108 | } |
| 109 | |
| 110 | encryptedData, err := encrypter.Encrypt(cert, plaintext, nil) |
| 111 | if err != nil { |
| 112 | return nil, err |
| 113 | } |
| 114 | encryptedData.CreateAttr("Type", "http://www.w3.org/2001/04/xmlenc#Element") |
| 115 | |
| 116 | encryptedID := etree.NewElement("saml:EncryptedID") |
| 117 | encryptedID.AddChild(encryptedData) |
| 118 | return encryptedID, nil |
| 119 | } |
| 120 | |
| 121 | // identifierBlockCiphers are the block ciphers identifierEncrypter may |
| 122 | // choose, in order of preference. AES-GCM comes first: CBC has no integrity |
no test coverage detected