github.com/safing/portbase@v0.19.5/utils/safe.go (about)

     1  package utils
     2  
     3  import (
     4  	"encoding/hex"
     5  	"strings"
     6  )
     7  
     8  // SafeFirst16Bytes return the first 16 bytes of the given data in safe form.
     9  func SafeFirst16Bytes(data []byte) string {
    10  	if len(data) == 0 {
    11  		return "<empty>"
    12  	}
    13  
    14  	return strings.TrimPrefix(
    15  		strings.SplitN(hex.Dump(data), "\n", 2)[0],
    16  		"00000000  ",
    17  	)
    18  }
    19  
    20  // SafeFirst16Chars return the first 16 characters of the given data in safe form.
    21  func SafeFirst16Chars(s string) string {
    22  	return SafeFirst16Bytes([]byte(s))
    23  }