summaryrefslogtreecommitdiffstats
path: root/enc/b64.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-08-29 13:28:16 -0400
committerrsiddharth <s@ricketyspace.net>2020-08-29 13:28:16 -0400
commitbd75e7268a8f5532f8348fcd82552ca8d38e7679 (patch)
treecae09ac9928001c90d67bfd790c5b44d0c6ca358 /enc/b64.go
parentb25b40ed05605e366f1d9410855ce36a01de8d4e (diff)
enc: fromHexChar -> HexCharToDec
* enc/b64.go (fromHexChar): Move and rename this function to... * enc/hex.go (HexCharToDec): ...this.
Diffstat (limited to 'enc/b64.go')
-rw-r--r--enc/b64.go18
1 files changed, 3 insertions, 15 deletions
diff --git a/enc/b64.go b/enc/b64.go
index 1e49b58..4c251a2 100644
--- a/enc/b64.go
+++ b/enc/b64.go
@@ -10,9 +10,9 @@ func HexToBase64(hex string) string {
b64 := ""
for i := 0; i <= len(hb)-3; i = i + 3 {
- a := (fromHexChar(hb[i])<<8 |
- fromHexChar(hb[i+1])<<4 |
- fromHexChar(hb[i+2]))
+ a := (HexCharToDec(hb[i])<<8 |
+ HexCharToDec(hb[i+1])<<4 |
+ HexCharToDec(hb[i+2]))
b64 += encode(a >> 6)
b64 += encode(a & 0b111111)
}
@@ -22,15 +22,3 @@ func HexToBase64(hex string) string {
func encode(b uint16) string {
return string(b64_table[b])
}
-
-// Adapted from
-// https://go.googlesource.com/go/+/refs/tags/go1.15/src/encoding/hex/hex.go#83
-func fromHexChar(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
-}