From a6f27c3faea924a509915ab679511033893b773f Mon Sep 17 00:00:00 2001 From: Shulhan Date: Mon, 29 Jan 2024 23:56:52 +0700 Subject: issuer: trim spaces on label and rawConfig parameter in NewIssuer If the label or rawConfig is empty, return an error immediately. --- issuer.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/issuer.go b/issuer.go index 3025be6..ed18919 100644 --- a/issuer.go +++ b/issuer.go @@ -32,14 +32,21 @@ type Issuer struct { // NewIssuer create and initialize new issuer from raw value. // If the rsaPrivateKey is not nil, that means the rawConfig is encrypted. func NewIssuer(label, rawConfig string, rsaPrivateKey *rsa.PrivateKey) (issuer *Issuer, err error) { - var ( - logp = `NewIssuer` + var logp = `NewIssuer` - vals []string - vbytes []byte - ) + label = strings.TrimSpace(label) + if len(label) == 0 { + return nil, fmt.Errorf(`%s: empty label`, logp) + } + + rawConfig = strings.TrimSpace(rawConfig) + if len(rawConfig) == 0 { + return nil, fmt.Errorf(`%s: empty configuration`, logp) + } if rsaPrivateKey != nil { + var vbytes []byte + vbytes, err = base64.StdEncoding.DecodeString(rawConfig) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) @@ -53,6 +60,8 @@ func NewIssuer(label, rawConfig string, rsaPrivateKey *rsa.PrivateKey) (issuer * rawConfig = string(vbytes) } + var vals []string + vals = strings.Split(rawConfig, valueSeparator) if len(vals) < 2 { return nil, fmt.Errorf(`%s: invalid value %q`, logp, rawConfig) -- cgit v1.3