本文整理汇总了Golang中github.com/lestrrat/go-libxml2/types.Document类的典型用法代码示例。如果您正苦于以下问题:Golang Document类的具体用法?Golang Document怎么用?Golang Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Document类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MakeXMLNode
func (sc SubjectConfirmation) MakeXMLNode(d types.Document) (types.Node, error) {
scxml, err := d.CreateElement(ns.SAML.AddPrefix("SubjectConfirmation"))
if err != nil {
return nil, err
}
scxml.MakeMortal()
defer scxml.AutoFree()
method := sc.Method
if sc.Method == "" {
method = Bearer
}
scxml.SetAttribute("Method", method.String())
scd, err := d.CreateElement(ns.SAML.AddPrefix("SubjectConfirmationData"))
if err != nil {
return nil, err
}
scd.SetAttribute("InResponseTo", sc.InResponseTo)
scd.SetAttribute("Recipient", sc.Recipient)
scd.SetAttribute("NotOnOrAfter", sc.NotOnOrAfter.Format(TimeFormat))
scxml.AddChild(scd)
scxml.MakePersistent()
return scxml, nil
}
示例2: XMLSecTmplSignatureCreateNsPref
func XMLSecTmplSignatureCreateNsPref(doc types.Document, c14nMethod TransformID, signMethod TransformID, id string, prefix string) (types.Node, error) {
docptr := (*C.xmlDoc)(unsafe.Pointer(doc.Pointer()))
if docptr == nil {
return nil, clib.ErrInvalidDocument
}
var xcid *C.xmlChar
if id != "" {
xcid = stringToXMLChar(id)
defer C.free(unsafe.Pointer(xcid))
}
var xcprefix *C.xmlChar
if prefix != "" {
xcprefix = stringToXMLChar(prefix)
defer C.free(unsafe.Pointer(xcprefix))
}
ptr := C.xmlSecTmplSignatureCreateNsPref(
docptr,
c14nMethod.ptr,
signMethod.ptr,
xcid,
xcprefix,
)
if ptr == nil {
return nil, errors.New("failed to create signature template")
}
return dom.WrapNode(uintptr(unsafe.Pointer(ptr)))
}
示例3: MakeXMLNode
func (m Message) MakeXMLNode(d types.Document) (types.Node, error) {
mxml, err := d.CreateElement("Message")
if err != nil {
return nil, err
}
mxml.MakeMortal()
defer mxml.AutoFree()
mxml.SetAttribute("ID", m.ID)
mxml.SetAttribute("Version", m.Version)
mxml.SetAttribute("IssueInstant", m.IssueInstant.Format(TimeFormat))
if v := m.Destination; v != "" {
mxml.SetAttribute("Destination", v)
}
if v := m.Consent; v != "" {
mxml.SetAttribute("Consent", v)
}
// XXX Comeback later.
iss, err := d.CreateElementNS(ns.SAML.URI, ns.SAML.AddPrefix("Issuer"))
if err != nil {
return nil, err
}
iss.AppendText(m.Issuer)
mxml.AddChild(iss)
mxml.MakePersistent()
return mxml, nil
}
示例4: XMLSecDSigCtxSignDocument
func XMLSecDSigCtxSignDocument(ctx PtrSource, doc types.Document) error {
ctxptr, err := validDSigCtxPtr(ctx)
if err != nil {
return err
}
root, err := doc.DocumentElement()
if err != nil {
return err
}
rootptr, err := validNodePtr(root)
if err != nil {
return err
}
cname := stringToXMLChar(SignatureNode)
cns := stringToXMLChar(DSigNs)
defer C.free(unsafe.Pointer(cname))
defer C.free(unsafe.Pointer(cns))
nodeptr := C.xmlSecFindNode(rootptr, cname, cns)
if nodeptr == nil {
return errors.New("failed to find start node")
}
return xmlSecDSigCtxSignRaw(ctxptr, nodeptr)
}
示例5: MakeXMLNode
func (nif Format) MakeXMLNode(doc types.Document) (types.Node, error) {
root, err := doc.CreateElement("md:NameIDFormat")
if err != nil {
return nil, err
}
root.AppendText(Transient)
return root, nil
}
示例6: constructAuthnRequest
func constructAuthnRequest(doc types.Document) (*AuthnRequest, error) {
root, err := doc.DocumentElement()
if err != nil {
return nil, errors.New("failed to fetch document element: " + err.Error())
}
ar := &AuthnRequest{}
if err := ar.PopulateFromXML(root); err != nil {
return nil, errors.New("failed to populate from xml: " + err.Error())
}
return ar, nil
}
示例7: MakeXMLNode
func (res Response) MakeXMLNode(d types.Document) (types.Node, error) {
oresxml, err := res.Message.MakeXMLNode(d)
if err != nil {
return nil, err
}
resxml := oresxml.(types.Element)
resxml.MakeMortal()
defer resxml.AutoFree()
resxml.SetNodeName("Response")
resxml.SetNamespace(ns.SAMLP.URI, ns.SAMLP.Prefix, true)
resxml.SetNamespace(ns.SAML.URI, ns.SAML.Prefix, false)
if v := res.InResponseTo; v != "" {
resxml.SetAttribute("InResponseTo", v)
}
st, err := d.CreateElement("samlp:Status")
if err != nil {
return nil, err
}
stc, err := d.CreateElement("samlp:StatusCode")
if err != nil {
return nil, err
}
stc.SetAttribute("Value", res.Status.String())
st.AddChild(stc)
resxml.AddChild(st)
if assertion := res.Assertion; assertion != nil {
axml, err := assertion.MakeXMLNode(d)
if err != nil {
return nil, err
}
resxml.AddChild(axml)
}
resxml.MakePersistent()
return resxml, nil
}
示例8: MakeXMLNode
func (kd KeyDescriptor) MakeXMLNode(doc types.Document) (types.Node, error) {
kdnode, err := doc.CreateElement("md:KeyDescriptor")
if err != nil {
return nil, err
}
defer kdnode.AutoFree()
kdnode.MakeMortal()
if v := kd.Use; v != "" {
kdnode.SetAttribute("use", v)
}
keynode, err := kd.Key.MakeXMLNode(doc)
if err != nil {
return nil, err
}
kdnode.AddChild(keynode)
kdnode.MakePersistent()
return kdnode, nil
}
示例9: XMLSecDSigCtxVerifyDocument
func XMLSecDSigCtxVerifyDocument(ctx PtrSource, doc types.Document) error {
ctxptr, err := validDSigCtxPtr(ctx)
if err != nil {
return err
}
root, err := doc.DocumentElement()
if err != nil {
return err
}
rootptr, err := validNodePtr(root)
if err != nil {
return err
}
nodeptr := findSignatureNode(rootptr)
if nodeptr == nil {
return errors.New("failed to find start node")
}
return XMLSecDSigCtxVerifyRaw(ctxptr, nodeptr)
}
示例10: MakeXMLNode
func (key *RSA) MakeXMLNode(doc types.Document) (types.Node, error) {
var root types.Node
var err error
prefix, err := doc.LookupNamespacePrefix(xmlsec.DSigNs)
if err != nil {
// namespace does not exist. make me a namespace
root, err = doc.CreateElementNS(xmlsec.DSigNs, xmlsec.Prefix+":KeyInfo")
if err != nil {
return nil, err
}
prefix = xmlsec.Prefix
} else {
root, err = doc.CreateElement(prefix + ":KeyInfo")
if err != nil {
return nil, err
}
}
defer root.AutoFree()
root.MakeMortal()
kvnode, err := doc.CreateElement(prefix + ":KeyValue")
if err != nil {
return nil, err
}
root.AddChild(kvnode)
rsakeynode, err := doc.CreateElement(prefix + ":RSAKeyValue")
if err != nil {
return nil, err
}
kvnode.AddChild(rsakeynode)
mnode, err := doc.CreateElement(prefix + ":Modulus")
if err != nil {
return nil, err
}
mnode.AppendText(base64.StdEncoding.EncodeToString(key.key.N.Bytes()))
rsakeynode.AddChild(mnode)
enode, err := doc.CreateElement(prefix + ":Exponent")
if err != nil {
return nil, err
}
data := make([]byte, 8)
binary.BigEndian.PutUint64(data, uint64(key.key.E))
i := 0
for ; i < len(data); i++ {
if data[i] != 0x0 {
break
}
}
enode.AppendText(base64.StdEncoding.EncodeToString(data[i:]))
rsakeynode.AddChild(enode)
root.MakePersistent()
return root, nil
}