From 3f6cfac8fd6f223786e49500b50bf2697d47cc89 Mon Sep 17 00:00:00 2001 From: "andrew.smith@miracl.com" Date: Mon, 31 Oct 2016 17:01:02 +0000 Subject: [PATCH] add URI attribute to --- signature.go | 53 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/signature.go b/signature.go index cb59e42..5c4d411 100644 --- a/signature.go +++ b/signature.go @@ -10,6 +10,18 @@ import ( type Method struct { Algorithm string `xml:",attr"` } +type Reference struct { + URI string `xml:"URI,attr"` + ReferenceTransforms []Method `xml:"Transforms>Transform"` + DigestMethod Method `xml:"DigestMethod"` + DigestValue string `xml:"DigestValue"` +} + +type SignedInfo struct { + CanonicalizationMethod Method `xml:"CanonicalizationMethod"` + SignatureMethod Method `xml:"SignatureMethod"` + Reference Reference `xml:"Reference"` +} // Signature is a model for the Signature object specified by XMLDSIG. This is // convenience object when constructing XML that you'd like to sign. For example: @@ -25,16 +37,11 @@ type Method struct { // buf, _ = Sign(key, buf) // type Signature struct { - XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# Signature"` - - CanonicalizationMethod Method `xml:"SignedInfo>CanonicalizationMethod"` - SignatureMethod Method `xml:"SignedInfo>SignatureMethod"` - ReferenceTransforms []Method `xml:"SignedInfo>Reference>Transforms>Transform"` - DigestMethod Method `xml:"SignedInfo>Reference>DigestMethod"` - DigestValue string `xml:"SignedInfo>Reference>DigestValue"` - SignatureValue string `xml:"SignatureValue"` - KeyName string `xml:"KeyInfo>KeyName,omitempty"` - X509Certificate *SignatureX509Data `xml:"KeyInfo>X509Data,omitempty"` + XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# Signature"` + SignedInfo SignedInfo + SignatureValue string `xml:"SignatureValue"` + KeyName string `xml:"KeyInfo>KeyName,omitempty"` + X509Certificate *SignatureX509Data `xml:"KeyInfo>X509Data,omitempty"` } // SignatureX509Data represents the element of @@ -50,17 +57,21 @@ func DefaultSignature(pemEncodedPublicKey []byte) Signature { certStr := base64.StdEncoding.EncodeToString(pemBlock.Bytes) return Signature{ - CanonicalizationMethod: Method{ - Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", - }, - SignatureMethod: Method{ - Algorithm: "http://www.w3.org/2000/09/xmldsig#rsa-sha1", - }, - ReferenceTransforms: []Method{ - Method{Algorithm: "http://www.w3.org/2000/09/xmldsig#enveloped-signature"}, - }, - DigestMethod: Method{ - Algorithm: "http://www.w3.org/2000/09/xmldsig#sha1", + SignedInfo: SignedInfo{ + CanonicalizationMethod: Method{ + Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", + }, + SignatureMethod: Method{ + Algorithm: "http://www.w3.org/2000/09/xmldsig#rsa-sha1", + }, + Reference: Reference{ + ReferenceTransforms: []Method{ + Method{Algorithm: "http://www.w3.org/2000/09/xmldsig#enveloped-signature"}, + }, + DigestMethod: Method{ + Algorithm: "http://www.w3.org/2000/09/xmldsig#sha1", + }, + }, }, X509Certificate: &SignatureX509Data{ X509Certificate: certStr,