Skip to content

Commit

Permalink
chore: upgrade deprecated stdlib functions
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Jan 2, 2024
1 parent bab3270 commit c501710
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/examples_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package examples

import (
"fmt"
"io/ioutil"
"io"
"os"

"github.com/moov-io/signedxml"
Expand All @@ -21,7 +21,7 @@ func testValidator() {
}
defer xmlFile.Close()

xmlBytes, _ := ioutil.ReadAll(xmlFile)
xmlBytes, _ := io.ReadAll(xmlFile)

validator, err := signedxml.NewValidator(string(xmlBytes))
if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions signedxml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/base64"
"encoding/pem"
"fmt"
"io/ioutil"
"io"
"os"
"testing"

Expand All @@ -14,17 +14,17 @@ import (
)

func TestSign(t *testing.T) {
pemString, _ := ioutil.ReadFile("./testdata/rsa.crt")
pemString, _ := os.ReadFile("./testdata/rsa.crt")
pemBlock, _ := pem.Decode([]byte(pemString))
cert, _ := x509.ParseCertificate(pemBlock.Bytes)

b64Bytes, _ := ioutil.ReadFile("./testdata/rsa.key.b64")
b64Bytes, _ := os.ReadFile("./testdata/rsa.key.b64")
pemString, _ = base64.StdEncoding.DecodeString(string(b64Bytes))
pemBlock, _ = pem.Decode([]byte(pemString))
key, _ := x509.ParsePKCS1PrivateKey(pemBlock.Bytes)

Convey("Given an XML, certificate, and RSA key", t, func() {
xml, _ := ioutil.ReadFile("./testdata/nosignature.xml")
xml, _ := os.ReadFile("./testdata/nosignature.xml")

Convey("When generating the signature", func() {
signer, _ := NewSigner(string(xml))
Expand All @@ -43,7 +43,7 @@ func TestSign(t *testing.T) {
})

Convey("Given an XML with http://www.w3.org/TR/2001/REC-xml-c14n-20010315 canonicalization, certificate, and RSA key", t, func() {
xml, _ := ioutil.ReadFile("./testdata/nosignature2.xml")
xml, _ := os.ReadFile("./testdata/nosignature2.xml")

Convey("When generating the signature", func() {
signer, _ := NewSigner(string(xml))
Expand All @@ -62,7 +62,7 @@ func TestSign(t *testing.T) {
})

Convey("Given an XML with custom referenceIDAttribute, certificate, and RSA key", t, func() {
xml, _ := ioutil.ReadFile("./testdata/nosignature-custom-reference-id-attribute.xml")
xml, _ := os.ReadFile("./testdata/nosignature-custom-reference-id-attribute.xml")

Convey("When generating the signature with custom referenceIDAttribute", func() {
signer, _ := NewSigner(string(xml))
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestValidate(t *testing.T) {
fmt.Println("Error opening file:", err)
}
defer xmlFile.Close()
xmlBytes, _ := ioutil.ReadAll(xmlFile)
xmlBytes, _ := io.ReadAll(xmlFile)
validator, _ := NewValidator(string(xmlBytes))
refs, err := validator.ValidateReferences()
Convey("Then no error occurs", func() {
Expand All @@ -134,7 +134,7 @@ func TestValidate(t *testing.T) {
xmlFile, _ := os.Open("./testdata/bbauth-metadata.xml")
sig := `<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><Reference URI="#_69b42076-409e-4476-af41-339962e49427"><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>LPHoiAkLmA/TGIuVbgpwlFLXL+ymEBc7TS0fC9/PTQU=</DigestValue></Reference></SignedInfo><SignatureValue>d2CXq9GEeDKvMxdpxtTRKQ8TGeSWhJOVPs8LMD0ObeE1t/YGiAm9keorMiki4laxbWqAuOmwHK3qNHogRFgkIYi3fnuFBzMrahXf0n3A5PRXXW1m768Z92GKV09pGuygKUXCtXzwq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3t8ZZepIXCwDaKo/oUp2h5Y9O3vyGDguq5ptgDTmPNYDCwWtdt0TtQYeLtCQTJVbYByWL0eT+KdzQOkAi48cPEOObSc9Biga7LTCcbCVPeJlYzmHDQUhzBt2jcy5BGvmZloI5SsoZvve6ug74qNq8IJMyzJzUp3kRuB0ruKIioSDi1lc783LDT3LSXyIbOGw/vHBEBY4Ax7FK8CqXJ2TsYqVsyo8QypqXDnveLcgK+PNEAhezhxC9hyV8j1I8pfF72ABE=</X509Certificate></X509Data></KeyInfo></Signature>`
defer xmlFile.Close()
xmlBytes, _ := ioutil.ReadAll(xmlFile)
xmlBytes, _ := io.ReadAll(xmlFile)
validator := Validator{}
validator.SetXML(string(xmlBytes))
validator.SetSignature(sig)
Expand All @@ -148,11 +148,11 @@ func TestValidate(t *testing.T) {

Convey("When Validate is called with an external certificate and root xmlns", func() {
xmlFile, _ := os.Open("./testdata/rootxmlns.xml")
pemString, _ := ioutil.ReadFile("./testdata/rootxmlns.crt")
pemString, _ := os.ReadFile("./testdata/rootxmlns.crt")
pemBlock, _ := pem.Decode([]byte(pemString))
cert, _ := x509.ParseCertificate(pemBlock.Bytes)
defer xmlFile.Close()
xmlBytes, _ := ioutil.ReadAll(xmlFile)
xmlBytes, _ := io.ReadAll(xmlFile)
validator := Validator{}
validator.SetXML(string(xmlBytes))
validator.Certificates = append(validator.Certificates, *cert)
Expand Down

0 comments on commit c501710

Please sign in to comment.