-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanonicalization_method.go
60 lines (47 loc) · 1.29 KB
/
canonicalization_method.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package xmldsig
import (
"errors"
"github.com/beevik/etree"
"github.com/deb-ict/go-xmldsig/canonicalizer"
)
type CanonicalizationMethod struct {
Algorithm string
signedInfo *SignedInfo
cachedXml *etree.Element
canonicalizer canonicalizer.Canonicalizer
}
func newCanonicalizationMethod(signedInfo *SignedInfo) *CanonicalizationMethod {
return &CanonicalizationMethod{
signedInfo: signedInfo,
}
}
func (xml *CanonicalizationMethod) root() *SignedXml {
return xml.signedInfo.root()
}
func (xml *CanonicalizationMethod) loadXml(el *etree.Element) error {
err := validateElement(el, "CanonicalizationMethod", XmlDSigNamespaceUri)
if err != nil {
return err
}
xml.Algorithm = el.SelectAttrValue("Algorithm", "")
canonicalizer, err := canonicalizer.LoadCanonicalizer(xml.Algorithm, el)
if err != nil {
return err
}
xml.canonicalizer = canonicalizer
xml.cachedXml = el
return nil
}
func (xml *CanonicalizationMethod) getXml() (*etree.Element, error) {
el := etree.NewElement("CanonicalizationMethod")
el.Space = xml.root().getElementSpace(XmlDSigNamespaceUri)
el.CreateAttr("Algorithm", xml.Algorithm)
if xml.canonicalizer == nil {
return nil, errors.New("canonicalizer is nil")
}
err := xml.canonicalizer.WriteXml(el)
if err != nil {
return nil, err
}
return el, nil
}