...

Source file src/github.com/sassoftware/relic/lib/xmldsig/structs.go

Documentation: github.com/sassoftware/relic/lib/xmldsig

     1  //
     2  // Copyright (c) SAS Institute Inc.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package xmldsig
    18  
    19  import (
    20  	"crypto"
    21  	"encoding/xml"
    22  )
    23  
    24  const (
    25  	NsXMLDsig        = "http://www.w3.org/2000/09/xmldsig#"
    26  	NsXMLDsigMore    = "http://www.w3.org/2001/04/xmldsig-more#"
    27  	NsXMLEnc         = "http://www.w3.org/2001/04/xmlenc#"
    28  	NsXsi            = "http://www.w3.org/2001/XMLSchema-instance"
    29  	AlgXMLExcC14n    = "http://www.w3.org/2001/10/xml-exc-c14n#"
    30  	AlgXMLExcC14nRec = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" // draft version
    31  
    32  	AlgDsigEnvelopedSignature = "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
    33  )
    34  
    35  // the best thing about namespaces is there are so many to choose from
    36  var nsPrefixes = []string{NsXMLDsig, NsXMLDsigMore, NsXMLEnc}
    37  
    38  var hashNames = map[crypto.Hash]string{
    39  	crypto.SHA1:   "sha1",
    40  	crypto.SHA224: "sha224",
    41  	crypto.SHA256: "sha256",
    42  	crypto.SHA384: "sha384",
    43  	crypto.SHA512: "sha512",
    44  }
    45  
    46  var HashUris = map[crypto.Hash]string{
    47  	crypto.SHA1:   NsXMLDsig + "sha1",
    48  	crypto.SHA224: NsXMLDsigMore + "sha224",
    49  	crypto.SHA256: NsXMLEnc + "sha256",
    50  	crypto.SHA384: NsXMLDsigMore + "sha384",
    51  	crypto.SHA512: NsXMLEnc + "sha512",
    52  }
    53  
    54  type signature struct {
    55  	XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# Signature"`
    56  
    57  	CanonicalizationMethod method    `xml:"SignedInfo>CanonicalizationMethod"`
    58  	SignatureMethod        method    `xml:"SignedInfo>SignatureMethod"`
    59  	Reference              reference `xml:"SignedInfo>Reference"`
    60  	SignatureValue         string    `xml:"SignatureValue"`
    61  	KeyName                string    `xml:"KeyInfo>KeyName,omitempty"`
    62  	KeyValue               *keyValue `xml:"KeyInfo>KeyValue,omitempty"`
    63  	X509Certificates       []string  `xml:"KeyInfo>X509Data>X509Certificate,omitempty"`
    64  }
    65  
    66  type reference struct {
    67  	URI          string   `xml:",attr"`
    68  	Transforms   []method `xml:"Transforms>Transform"`
    69  	DigestMethod method
    70  	DigestValue  string
    71  }
    72  
    73  type method struct {
    74  	Algorithm string `xml:",attr"`
    75  }
    76  
    77  type keyValue struct {
    78  	Modulus    string     `xml:"RSAKeyValue>Modulus,omitempty"`
    79  	Exponent   string     `xml:"RSAKeyValue>Exponent,omitempty"`
    80  	NamedCurve namedCurve `xml:"ECDSAKeyValue>DomainParameters>NamedCurve,omitempty"`
    81  	X          pointValue `xml:"ECDSAKeyValue>PublicKey>X,omitempty"`
    82  	Y          pointValue `xml:"ECDSAKeyValue>PublicKey>Y,omitempty"`
    83  }
    84  
    85  type namedCurve struct {
    86  	URN string `xml:",attr"`
    87  }
    88  
    89  type pointValue struct {
    90  	Value string `xml:",attr"`
    91  }
    92  

View as plain text