get rid of hacky newDoc2()
This commit is contained in:
@@ -48,7 +48,7 @@ func Decrypt(privateKey []byte, doc []byte) ([]byte, error) {
|
||||
return nil, popError()
|
||||
}
|
||||
|
||||
parsedDoc, err := newDoc(doc)
|
||||
parsedDoc, err := newDoc(doc, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func Encrypt(publicKey, doc []byte, opts EncryptOptions) ([]byte, error) {
|
||||
return nil, mustPopError()
|
||||
}
|
||||
|
||||
parsedDoc, err := newDoc(doc)
|
||||
parsedDoc, err := newDoc(doc, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ func (testSuite *EncryptTest) TestEncrypt(c *C) {
|
||||
actualPlaintext, err := Decrypt(testSuite.Key, encryptedString)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
plaintextDoc, _ := newDoc(testSuite.Plaintext)
|
||||
plaintextDoc, _ := newDoc(testSuite.Plaintext, nil)
|
||||
expectedPlaintext := dumpDoc(plaintextDoc)
|
||||
|
||||
// Big blobs of XML are hard to debug. They are easier to handle when
|
||||
|
||||
@@ -58,7 +58,7 @@ func Sign(key []byte, doc []byte, opts SignatureOptions) ([]byte, error) {
|
||||
return nil, errors.New("failed to load pem key")
|
||||
}
|
||||
|
||||
parsedDoc, err := newDoc2(doc, opts)
|
||||
parsedDoc, err := newDoc(doc, opts.XMLID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func Verify(publicKey []byte, doc []byte, opts SignatureOptions) error {
|
||||
}
|
||||
defer C.xmlSecDSigCtxDestroy(dsigCtx)
|
||||
|
||||
parsedDoc, err := newDoc2(doc, opts)
|
||||
parsedDoc, err := newDoc(doc, opts.XMLID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
26
xmlsec.go
26
xmlsec.go
@@ -49,7 +49,7 @@ func init() {
|
||||
C.xmlSecErrorsSetCallback((C.xmlSecErrorsCallback)(unsafe.Pointer(C.onError_cgo)))
|
||||
}
|
||||
|
||||
func newDoc(buf []byte) (*C.xmlDoc, error) {
|
||||
func newDoc(buf []byte, idattrs []XMLIDOption) (*C.xmlDoc, error) {
|
||||
ctx := C.xmlCreateMemoryParserCtxt((*C.char)(unsafe.Pointer(&buf[0])),
|
||||
C.int(len(buf)))
|
||||
if ctx == nil {
|
||||
@@ -68,29 +68,7 @@ func newDoc(buf []byte) (*C.xmlDoc, error) {
|
||||
return nil, errors.New("parse failed")
|
||||
}
|
||||
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
func newDoc2(buf []byte, opts SignatureOptions) (*C.xmlDoc, error) {
|
||||
ctx := C.xmlCreateMemoryParserCtxt((*C.char)(unsafe.Pointer(&buf[0])),
|
||||
C.int(len(buf)))
|
||||
if ctx == nil {
|
||||
return nil, errors.New("error creating parser")
|
||||
}
|
||||
defer C.xmlFreeParserCtxt(ctx)
|
||||
|
||||
C.xmlParseDocument(ctx)
|
||||
|
||||
if ctx.wellFormed == C.int(0) {
|
||||
return nil, errors.New("malformed XML")
|
||||
}
|
||||
|
||||
doc := ctx.myDoc
|
||||
if doc == nil {
|
||||
return nil, errors.New("parse failed")
|
||||
}
|
||||
|
||||
for _, idattr := range opts.XMLID {
|
||||
for _, idattr := range idattrs {
|
||||
addIDAttr(C.xmlDocGetRootElement(doc),
|
||||
idattr.AttributeName, idattr.ElementName, idattr.ElementNamespace)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user