From bd75e7268a8f5532f8348fcd82552ca8d38e7679 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 29 Aug 2020 13:28:16 -0400 Subject: enc: fromHexChar -> HexCharToDec * enc/b64.go (fromHexChar): Move and rename this function to... * enc/hex.go (HexCharToDec): ...this. --- enc/hex.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 enc/hex.go (limited to 'enc/hex.go') 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 +// 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 +} -- cgit v1.2.3