xml_constants.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package dsig
  2. import "crypto"
  3. const (
  4. DefaultPrefix = "ds"
  5. Namespace = "http://www.w3.org/2000/09/xmldsig#"
  6. )
  7. // Tags
  8. const (
  9. SignatureTag = "Signature"
  10. SignedInfoTag = "SignedInfo"
  11. CanonicalizationMethodTag = "CanonicalizationMethod"
  12. SignatureMethodTag = "SignatureMethod"
  13. ReferenceTag = "Reference"
  14. TransformsTag = "Transforms"
  15. TransformTag = "Transform"
  16. DigestMethodTag = "DigestMethod"
  17. DigestValueTag = "DigestValue"
  18. SignatureValueTag = "SignatureValue"
  19. KeyInfoTag = "KeyInfo"
  20. X509DataTag = "X509Data"
  21. X509CertificateTag = "X509Certificate"
  22. InclusiveNamespacesTag = "InclusiveNamespaces"
  23. )
  24. const (
  25. AlgorithmAttr = "Algorithm"
  26. URIAttr = "URI"
  27. DefaultIdAttr = "ID"
  28. PrefixListAttr = "PrefixList"
  29. )
  30. type AlgorithmID string
  31. func (id AlgorithmID) String() string {
  32. return string(id)
  33. }
  34. const (
  35. RSASHA1SignatureMethod = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
  36. RSASHA256SignatureMethod = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
  37. RSASHA512SignatureMethod = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"
  38. )
  39. //Well-known signature algorithms
  40. const (
  41. // Supported canonicalization algorithms
  42. CanonicalXML10ExclusiveAlgorithmId AlgorithmID = "http://www.w3.org/2001/10/xml-exc-c14n#"
  43. CanonicalXML11AlgorithmId AlgorithmID = "http://www.w3.org/2006/12/xml-c14n11"
  44. CanonicalXML10RecAlgorithmId AlgorithmID = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
  45. CanonicalXML10CommentAlgorithmId AlgorithmID = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
  46. EnvelopedSignatureAltorithmId AlgorithmID = "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
  47. )
  48. var digestAlgorithmIdentifiers = map[crypto.Hash]string{
  49. crypto.SHA1: "http://www.w3.org/2000/09/xmldsig#sha1",
  50. crypto.SHA256: "http://www.w3.org/2001/04/xmlenc#sha256",
  51. crypto.SHA512: "http://www.w3.org/2001/04/xmlenc#sha512",
  52. }
  53. var digestAlgorithmsByIdentifier = map[string]crypto.Hash{}
  54. var signatureMethodsByIdentifier = map[string]crypto.Hash{}
  55. func init() {
  56. for hash, id := range digestAlgorithmIdentifiers {
  57. digestAlgorithmsByIdentifier[id] = hash
  58. }
  59. for hash, id := range signatureMethodIdentifiers {
  60. signatureMethodsByIdentifier[id] = hash
  61. }
  62. }
  63. var signatureMethodIdentifiers = map[crypto.Hash]string{
  64. crypto.SHA1: RSASHA1SignatureMethod,
  65. crypto.SHA256: RSASHA256SignatureMethod,
  66. crypto.SHA512: RSASHA512SignatureMethod,
  67. }