Replace deprecated ioutil package

This commit is contained in:
Paul van Brouwershaven
2023-02-20 15:46:37 +01:00
parent 9d4a20b926
commit 007b08d4d1
4 changed files with 13 additions and 14 deletions

View File

@@ -8,7 +8,7 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strconv" "strconv"
@@ -269,7 +269,7 @@ func (context *SignContext) GetTSA(sign_content []byte) (timestamp_response []by
if err != nil || (code < 200 || code > 299) { if err != nil || (code < 200 || code > 299) {
if err == nil { if err == nil {
defer resp.Body.Close() defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
return nil, errors.New("non success response (" + strconv.Itoa(code) + "): " + string(body)) return nil, errors.New("non success response (" + strconv.Itoa(code) + "): " + string(body))
} }
@@ -277,7 +277,7 @@ func (context *SignContext) GetTSA(sign_content []byte) (timestamp_response []by
} }
defer resp.Body.Close() defer resp.Body.Close()
timestamp_response_body, err := ioutil.ReadAll(resp.Body) timestamp_response_body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read response: %w", err) return nil, fmt.Errorf("failed to read response: %w", err)
} }

View File

@@ -4,7 +4,7 @@ import (
"crypto/x509" "crypto/x509"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
@@ -27,7 +27,7 @@ func embedOCSPRevocationStatus(cert, issuer *x509.Certificate, i *revocation.Inf
return err return err
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }
@@ -49,7 +49,7 @@ func embedCRLRevocationStatus(cert, issuer *x509.Certificate, i *revocation.Info
return err return err
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

File diff suppressed because one or more lines are too long

View File

@@ -7,7 +7,6 @@ import (
"encoding/asn1" "encoding/asn1"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"reflect" "reflect"
"time" "time"
@@ -146,7 +145,7 @@ func Reader(file io.ReaderAt, size int64) (apiResp *Response, err error) {
// This content will be hashed with the corresponding algorithm to // This content will be hashed with the corresponding algorithm to
// verify the signature. // verify the signature.
content, err := ioutil.ReadAll(io.NewSectionReader(file, v.Key("ByteRange").Index(i-1).Int64(), v.Key("ByteRange").Index(i).Int64())) content, err := io.ReadAll(io.NewSectionReader(file, v.Key("ByteRange").Index(i-1).Int64(), v.Key("ByteRange").Index(i).Int64()))
if err != nil { if err != nil {
apiResp.Error = fmt.Sprintln("Failed to get ByteRange:", i, err) apiResp.Error = fmt.Sprintln("Failed to get ByteRange:", i, err)
} }