NewFixedStringHash creates a FixedString from a hash of all the passed in strings
(args ...string)
| 85 | |
| 86 | // NewFixedStringHash creates a FixedString from a hash of all the passed in strings |
| 87 | func NewFixedStringHash(args ...string) (FixedString, error) { |
| 88 | if len(args) == 0 { |
| 89 | return FixedString{}, errors.New("no arguments provided") |
| 90 | } |
| 91 | |
| 92 | joined := strings.Join(args, "") |
| 93 | if joined == "" { |
| 94 | return FixedString{}, errors.New("joined string is empty") |
| 95 | } |
| 96 | |
| 97 | // #nosec |
| 98 | hash := md5.Sum([]byte(strings.Join(args, ""))) |
| 99 | |
| 100 | fs := FixedString{ |
| 101 | Data: hash, |
| 102 | } |
| 103 | return fs, nil |
| 104 | } |
| 105 | |
| 106 | // NewFixedStringFromString creates a FixedString from a passed in hex string |
| 107 | func NewFixedStringFromHex(h string) (FixedString, error) { |
no outgoing calls