xmldsig: switch to using gocheck and add tests

This commit is contained in:
Ross Kinder
2015-11-30 20:14:58 -05:00
parent 7f65c2aa7b
commit ded02b064c
2 changed files with 87 additions and 59 deletions

View File

@@ -79,32 +79,28 @@ func newDoc(buf []byte, opts Options) (*C.xmlDoc, error) {
} }
for _, idattr := range opts.XMLID { for _, idattr := range opts.XMLID {
if err := addIDAttr(C.xmlDocGetRootElement(doc), addIDAttr(C.xmlDocGetRootElement(doc),
idattr.AttributeName, idattr.ElementName, idattr.ElementNamespace); err != nil { idattr.AttributeName, idattr.ElementName, idattr.ElementNamespace)
return nil, err
}
} }
return doc, nil return doc, nil
} }
func addIDAttr(node *C.xmlNode, attrName, nodeName, nsHref string) error { func addIDAttr(node *C.xmlNode, attrName, nodeName, nsHref string) {
// process children first because it does not matter much but does simplify code // process children first because it does not matter much but does simplify code
cur := C.xmlSecGetNextElementNode(node.children) cur := C.xmlSecGetNextElementNode(node.children)
for { for {
if cur == nil { if cur == nil {
break break
} }
if err := addIDAttr(cur, attrName, nodeName, nsHref); err != nil { addIDAttr(cur, attrName, nodeName, nsHref)
return err
}
cur = C.xmlSecGetNextElementNode(cur.next) cur = C.xmlSecGetNextElementNode(cur.next)
} }
if C.GoString((*C.char)(unsafe.Pointer(node.name))) != nodeName { if C.GoString((*C.char)(unsafe.Pointer(node.name))) != nodeName {
return nil return
} }
if nsHref != "" && node.ns != nil && C.GoString((*C.char)(unsafe.Pointer(node.ns.href))) != nsHref { if nsHref != "" && node.ns != nil && C.GoString((*C.char)(unsafe.Pointer(node.ns.href))) != nsHref {
return nil return
} }
// the attribute with name equal to attrName should exist // the attribute with name equal to attrName should exist
@@ -118,7 +114,7 @@ func addIDAttr(node *C.xmlNode, attrName, nodeName, nsHref string) error {
} }
} }
return nil return
} }
func dumpDoc(doc *C.xmlDoc) []byte { func dumpDoc(doc *C.xmlDoc) []byte {

File diff suppressed because one or more lines are too long