hash

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 6 Imported by: 3

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

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

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

type ObjectHasher

type ObjectHasher interface {
	Hash(obj any) string
	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

type Set added in v0.7.0

type Set[T any] map[string]T

Set is a set that stores objects based on their Object hash

func NewSet added in v0.7.0

func NewSet[T any](objects ...T) Set[T]

NewSet creates a set from a list of objects

func (Set[T]) Contains added in v0.7.0

func (s Set[T]) Contains(other Set[T]) bool

Contains returns true if all elements of other can be found in s.

func (Set[T]) Delete added in v0.7.0

func (s Set[T]) Delete(objects ...T) Set[T]

Delete removes all objects from the set

func (Set[T]) EqualElements added in v0.7.0

func (s Set[T]) EqualElements(other Set[T]) bool

EqualElements returns true if both sets have equal elements.

func (Set[T]) Has added in v0.7.0

func (s Set[T]) Has(objects ...T) bool

Has returns true if all objects are already in the set

func (Set[T]) Insert added in v0.7.0

func (s Set[T]) Insert(objects ...T) Set[T]

Insert adds all objects to the set

func (Set[T]) Intersect added in v0.7.0

func (s Set[T]) Intersect(other Set[T]) Set[T]

Intersect returns a new set containing all the elements common to both. The new set will contain the object values from the receiver, not from the argument.

func (Set[T]) Len added in v0.7.0

func (s Set[T]) Len() int

Len returns the number of objects in the set

func (Set[T]) Pop added in v0.7.0

func (s Set[T]) Pop() (T, bool)

Pop removes and returns a single element from the set, and a bool indicating whether an element was found to pop.

func (Set[T]) SetDifference added in v0.7.0

func (s Set[T]) SetDifference(other Set[T]) Set[T]

SetDifference returns the set of objects in s that are not in other.

func (Set[T]) Union added in v0.7.0

func (s Set[T]) Union(other Set[T]) Set[T]

Union returns the set of objects common to both sets.

Jump to

Keyboard shortcuts

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