github.com/crewjam/saml@v0.4.14/xmlenc/digest.go (about) 1 package xmlenc 2 3 import ( 4 "crypto/sha1" //nolint:gosec // required for protocol support 5 "crypto/sha256" 6 "crypto/sha512" 7 "hash" 8 9 //nolint:staticcheck // We should support this for legacy reasons. 10 "golang.org/x/crypto/ripemd160" 11 ) 12 13 type digestMethod struct { 14 algorithm string 15 hash func() hash.Hash 16 } 17 18 func (dm digestMethod) Algorithm() string { 19 return dm.algorithm 20 } 21 22 func (dm digestMethod) Hash() hash.Hash { 23 return dm.hash() 24 } 25 26 var ( 27 // SHA1 implements the SHA-1 digest method (which is considered insecure) 28 SHA1 = digestMethod{ 29 algorithm: "http://www.w3.org/2000/09/xmldsig#sha1", 30 hash: sha1.New, 31 } 32 33 // SHA256 implements the SHA-256 digest method 34 SHA256 = digestMethod{ 35 algorithm: "http://www.w3.org/2000/09/xmldsig#sha256", 36 hash: sha256.New, 37 } 38 39 // SHA512 implements the SHA-512 digest method 40 SHA512 = digestMethod{ 41 algorithm: "http://www.w3.org/2000/09/xmldsig#sha512", 42 hash: sha512.New, 43 } 44 45 // RIPEMD160 implements the RIPEMD160 digest method 46 RIPEMD160 = digestMethod{ 47 algorithm: "http://www.w3.org/2000/09/xmldsig#ripemd160", 48 hash: ripemd160.New, 49 } 50 ) 51 52 func init() { 53 RegisterDigestMethod(SHA1) 54 RegisterDigestMethod(SHA256) 55 RegisterDigestMethod(SHA512) 56 RegisterDigestMethod(RIPEMD160) 57 }