"Sputnik" help  
Sputnik Help


Creates a copy of a hash context, allowing for the preservation of a snapshot of the hash state at a specific point in the computation.


<hashContext> The hash context to be copied.

Return Value

Success: Returns a new hash context that is an exact copy of the specified <hashContext>.
Failure: Returns null.


HashCopy is useful when it's necessary to maintain multiple instances of a hash context, preserving different states during a hashing operation. This function allows for the creation of snapshots, which can be independently updated and finalized.



Example of usage

my $hash = HashInit("gost");
HashUpdate($hash, "Cat");
my $hash2 = HashCopy($hash);
HashUpdate($hash, "Dog");
say HashFinal($hash);
HashUpdate($hash2, "Dog");
say HashFinal($hash2);

// 5D32789DD6F8F25FBDEE44F875FABC1556AE8A97F3619EE8CE04D548595D0973
// 5D32789DD6F8F25FBDEE44F875FABC1556AE8A97F3619EE8CE04D548595D0973

In the provided example, a hash context is initialized using the GOST hash algorithm with HashInit("gost"). The HashUpdate function is then used to update this context with the string "Cat." Subsequently, a copy of the original hash context is created using HashCopy($hash). Even though the original hash context is further updated with the string "Dog," the copied hash context, $hash2, remains unaffected by these additional updates. The final hash values obtained from both contexts demonstrate that the state of the copied hash context accurately reflects its state at the point of copying. This showcases the effectiveness of HashCopy in creating independent snapshots of the hash state, allowing for parallel or independent hashing operations without affecting each other.

Cheryl (uberfox@hotmail.com)