diff options
author | rsiddharth <s@ricketyspace.net> | 2020-08-29 13:28:16 -0400 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-08-29 13:28:16 -0400 |
commit | bd75e7268a8f5532f8348fcd82552ca8d38e7679 (patch) | |
tree | cae09ac9928001c90d67bfd790c5b44d0c6ca358 /enc/hex.go | |
parent | b25b40ed05605e366f1d9410855ce36a01de8d4e (diff) |
enc: fromHexChar -> HexCharToDec
* enc/b64.go (fromHexChar): Move and rename this function to...
* enc/hex.go (HexCharToDec): ...this.
Diffstat (limited to 'enc/hex.go')
-rw-r--r-- | enc/hex.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/enc/hex.go b/enc/hex.go new file mode 100644 index 0000000..0d19538 --- /dev/null +++ b/enc/hex.go @@ -0,0 +1,16 @@ +// Copyright © 2020 rsiddharth <s@ricketyspace.net> +// SPDX-License-Identifier: ISC + +package enc + +// Adapted from +// https://go.googlesource.com/go/+/refs/tags/go1.15/src/encoding/hex/hex.go#83 +func HexCharToDec(c byte) uint16 { + switch { + case '0' <= c && c <= '9': + return uint16(c - '0') + case 'a' <= c && c <= 'f': + return uint16(c - 'a' + 10) + } + return 0 +} |