keyBytesFromStr converts a string of binary bits to a byte slice CONTRACT: str must be < than 8 bits
(str string)
| 2086 | // keyBytesFromStr converts a string of binary bits to a byte slice |
| 2087 | // CONTRACT: str must be < than 8 bits |
| 2088 | func keyBytesFromStr(str string) []byte { |
| 2089 | // create a new key from the byts |
| 2090 | var byts []byte |
| 2091 | if str != "" { |
| 2092 | leftPadding := 0 |
| 2093 | for _, ch := range str { |
| 2094 | if ch != '0' { |
| 2095 | break |
| 2096 | } |
| 2097 | leftPadding++ |
| 2098 | } |
| 2099 | if leftPadding == len(str) { |
| 2100 | leftPadding-- |
| 2101 | } |
| 2102 | val, _ := strconv.ParseUint(str, 2, 8) |
| 2103 | // convert the bits to bytes now producing the key |
| 2104 | byts = []byte{byte(val), byte(leftPadding)} |
| 2105 | } |
| 2106 | // return the key bytes |
| 2107 | return byts |
| 2108 | } |
no outgoing calls
no test coverage detected