diff options
| author | Shulhan <ms@kilabit.info> | 2024-01-29 23:56:52 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-01-29 23:56:52 +0700 |
| commit | a6f27c3faea924a509915ab679511033893b773f (patch) | |
| tree | 32f8db3f0a78743c893f24002377b52ef5490d73 | |
| parent | 1b26cbde7cc7f8488fa5df3c37c9b0163a921631 (diff) | |
| download | gotp-a6f27c3faea924a509915ab679511033893b773f.tar.xz | |
issuer: trim spaces on label and rawConfig parameter in NewIssuer
If the label or rawConfig is empty, return an error immediately.
| -rw-r--r-- | issuer.go | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -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) |
