hash

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2022 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

Package hash provides common utilities hashing kube objects and comparing hashes.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(a, b string) bool

Equal compares hashes safely

func Object

func Object(obj interface{}) (string, error)

Object canonicalizes the object before hashing with xxhash

Example
configmap := corev1.ConfigMap{
	Data: map[string]string{
		"some": "data",
	},
}
hash, _ := Object(configmap)
fmt.Println(Equal(hash, "n688h54h56ch64bh677h55fh648hddq"))
Output:

true

func SecureEqual

func SecureEqual(a, b string) bool

SecureEqual compares hashes safely

func SecureObject

func SecureObject(obj interface{}) (string, error)

SecureObject canonicalizes the object before hashing with sha512 and then with xxhash

Example
secret := corev1.Secret{
	StringData: map[string]string{
		"some": "data",
	},
}
hash, _ := SecureObject(secret)
fmt.Println(SecureEqual(hash, "n665hb8h667h68hfbhffh669h54dq"))
Output:

true

Types

type EqualFunc

type EqualFunc func(a, b string) bool

type ObjectHashFunc

type ObjectHashFunc func(obj any) (string, error)

type ObjectHasher

type ObjectHasher interface {
	Hash(obj any) (string, error)
	Equal(a, b string) bool
}

ObjectHasher hashes and object and can compare hashes for equality

func NewObjectHash

func NewObjectHash() ObjectHasher

NewObjectHash returns a new ObjectHasher using Object

func NewSecureObjectHash

func NewSecureObjectHash() ObjectHasher

NewSecureObjectHash returns a new ObjectHasher using SecureObject

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL