decodeNonce returns the nonce in bytes. If the input has the prefix base64: it will decode the rest using the base64 standard encoding.
(in string)
| 48 | // decodeNonce returns the nonce in bytes. If the input has the prefix base64: |
| 49 | // it will decode the rest using the base64 standard encoding. |
| 50 | func decodeNonce(in string) ([]byte, error) { |
| 51 | nonce := []byte(in) |
| 52 | switch { |
| 53 | case strings.HasPrefix(in, "string:"): |
| 54 | return nonce[7:], nil |
| 55 | case strings.HasPrefix(in, "base64:"): |
| 56 | input := nonce[7:] |
| 57 | nonce = make([]byte, base64.StdEncoding.DecodedLen(len(input))) |
| 58 | n, err := base64.StdEncoding.Decode(nonce, input) |
| 59 | if err != nil { |
| 60 | return nil, errors.Wrap(err, "error decoding base64 nonce") |
| 61 | } |
| 62 | return nonce[:n], nil |
| 63 | default: |
| 64 | return nonce, nil |
| 65 | } |
| 66 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…