Documentation
¶
Overview ¶
The HashingContext class provides an interface for computing cryptographic hashes over multiple iterations. Useful for computing hashes of big files (so you don't have to load them all in memory), network streams, and data streams in general (so you don't have to hold buffers).
The HashType enum shows the supported hashing algorithms.
package main import ( "encoding/hex" "fmt" "graphics.gd/classdb/FileAccess" "graphics.gd/classdb/HashingContext" ) const ChunkSize = 1024 func HashFile(path string) { if !FileAccess.FileExists(path) { return } var ctx = HashingContext.New() ctx.Start(HashingContext.HashSha256) var file = FileAccess.Open(path, FileAccess.Read) for file.GetPosition() < file.GetLength() { remaining := int(file.GetLength() - file.GetPosition()) ctx.Update(file.GetBuffer(min(remaining, ChunkSize))) } res := ctx.Finish() fmt.Println(hex.EncodeToString(res), res) }
Index ¶
- type Advanced
- type Any
- type Extension
- type HashType
- type ID
- type Instance
- func (self Instance) AsHashingContext() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) Finish() []byte
- func (self Instance) ID() ID
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Start(atype HashType) error
- func (self Instance) Update(chunk []byte) error
- func (self Instance) Virtual(name string) reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsHashingContext ¶
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.HashingContext
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsHashingContext ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) Start ¶
Starts a new hash computation of the given 'type' (e.g. HashSha256 to start computation of an SHA-256).