Skip to content
Snippets Groups Projects
Select Git revision
  • manage_sherd_folders
  • master default protected
  • host_financial_metrics
  • err-not-found
  • debug_maxcollateral_zero
  • add_providerlist_in_host_api
  • wallet_start_if_transporter_unavail
  • test-forks
  • debug-prints
  • disable_old_tls
  • wallet-improve-defrag
  • 231-reject-zero-storageprice-setting
  • client-ctx
  • fork2-spfb-geo-review
  • attach-bad-file-size-logs
  • renewal-debug-logs
  • create_sectorfile_as_sparse
  • cakiwi-changes-1
  • 216-externalize-build-tags
  • new-ci-integration
  • v1.9.3
  • v1.9.2
  • v1.9.1
  • v1.9.0
  • v1.8.4
  • v1.8.3
  • v1.8.0
  • v1.7.2
  • v1.7.1
  • v1.7.0
  • v1.6.6
  • v1.6.5
  • v1.6.4
  • v1.6.3.1
  • v1.6.3
  • v1.6.2
  • 1.6.1
  • v1.6.0
  • v1.5.3
  • v1.5.2
40 results

hex.go

Code owners
Assign users and groups as approvers for specific file changes. Learn more.
hex.go 724 B
package encoding

import (
	"encoding/hex"
	"errors"
)

// HexStringToBytes converts a hex encoded string (but as go type interface{}) to a byteslice
// If v is no valid string or the string contains invalid characters, an error is returned
func HexStringToBytes(v interface{}) (result []byte, err error) {
	var ok bool
	var stringValue string
	if stringValue, ok = v.(string); !ok {
		return nil, errors.New("Not a valid string")
	}
	if result, err = hex.DecodeString(stringValue); err != nil {
		return nil, errors.New("Not a valid hexadecimal value")
	}
	return
}

// BytesToHexString converts a byte slice to a hex encoded string
func BytesToHexString(bytes []byte) (result string) {
	return hex.EncodeToString(bytes)
}