envelopedsignature.go 957 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package signedxml
  2. import (
  3. "errors"
  4. "github.com/beevik/etree"
  5. )
  6. // EnvelopedSignature implements the CanonicalizationAlgorithm
  7. // interface and is used for processing the
  8. // http://www.w3.org/2000/09/xmldsig#enveloped-signature transform
  9. // algorithm
  10. type EnvelopedSignature struct{}
  11. // Process is called to transfrom the XML using the EnvelopedSignature
  12. // algorithm
  13. func (e EnvelopedSignature) Process(inputXML string,
  14. transformXML string) (outputXML string, err error) {
  15. doc := etree.NewDocument()
  16. doc.ReadFromString(inputXML)
  17. sig := doc.FindElement(".//Signature")
  18. if sig == nil {
  19. return "", errors.New("signedxml: unable to find Signature node")
  20. }
  21. sigParent := sig.Parent()
  22. elem := sigParent.RemoveChild(sig)
  23. if elem == nil {
  24. return "", errors.New("signedxml: unable to remove Signature element")
  25. }
  26. docString, err := doc.WriteToString()
  27. if err != nil {
  28. return "", err
  29. }
  30. //logger.Println(docString)
  31. return docString, nil
  32. }