This module provides various hashing algorithms for use within Hammerspoon.
The currently supported hash types can be viewed by examining the hs.hash.types constant.
In keeping with common hash library conventions to simplify the future addition of additional hash types, hash calculations in this module are handled in a three step manner, which is reflected in the constructor and methods defined for this module:
hashObject:append(data1):append(data2)
is different than hashObject:append(data2):append(data1)
.Most of the time, we only want to generate a hash value for a single data object; for this reason, meta-methods for this module allow you to use the following shortcut when computing a hash value:
hs.hash.<name>(data)
will return the hexadecimal version of the hash for the hash type <name>
where <name>
is one of the entries in hs.hash.types. This is syntacticly identical to hs.hash.new(<name>):append(data):finish():value()
.hs.hash.b<name>(data)
will return the binary version of the hash for the hash type '<name>'. This is syntacticly identical to hs.hash.new(<name>):append(data):finish():value(true)
.hmac
, the arguments should be (secret, data)
, but otherwise act as described above. If additional shared key hash algorithms are added, this will be adjusted to continue to allow the shortcuts for the most common usage patterns.The SHA3 code is based on code from the https://github.com/rhash/RHash project. https://github.com/krzyzanowskim/CryptoSwift may also prove useful for future additions.
Signature | hs.hash.bMD5(data) -> data |
---|---|
Type | Deprecated |
Description | Calculates a binary MD5 hash |
Notes |
|
Source | extensions/hash/hash.lua line 119 |
Signature | hs.hash.bSHA1(data) -> data |
---|---|
Type | Deprecated |
Description | Calculates a binary SHA1 hash |
Notes |
|
Source | extensions/hash/hash.lua line 80 |
Signature | hs.hash.bSHA256(data) -> data |
---|---|
Type | Deprecated |
Description | Calculates a binary SHA256 hash |
Notes |
|
Source | extensions/hash/hash.lua line 93 |
Signature | hs.hash.bSHA512(data) -> data |
---|---|
Type | Deprecated |
Description | Calculates a binary SHA512 hash |
Notes |
|
Source | extensions/hash/hash.lua line 106 |
Signature | hs.hash.hmacMD5(key, data) -> string |
---|---|
Type | Deprecated |
Description | Calculates an HMAC using a key and an MD5 hash |
Notes |
|
Source | extensions/hash/hash.lua line 174 |
Signature | hs.hash.hmacSHA1(key, data) -> string |
---|---|
Type | Deprecated |
Description | Calculates an HMAC using a key and a SHA1 hash |
Notes |
|
Source | extensions/hash/hash.lua line 132 |
Signature | hs.hash.hmacSHA256(key, data) -> string |
---|---|
Type | Deprecated |
Description | Calculates an HMAC using a key and a SHA256 hash |
Notes |
|
Source | extensions/hash/hash.lua line 146 |
Signature | hs.hash.hmacSHA512(key, data) -> string |
---|---|
Type | Deprecated |
Description | Calculates an HMAC using a key and a SHA512 hash |
Notes |
|
Source | extensions/hash/hash.lua line 160 |
Signature | hs.hash.MD5(data) -> string |
---|---|
Type | Deprecated |
Description | Calculates an MD5 hash |
Notes |
|
Source | extensions/hash/hash.lua line 67 |
Signature | hs.hash.SHA1(data) -> string |
---|---|
Type | Deprecated |
Description | Calculates an SHA1 hash |
Notes |
|
Source | extensions/hash/hash.lua line 28 |
Signature | hs.hash.SHA256(data) -> string |
---|---|
Type | Deprecated |
Description | Calculates an SHA256 hash |
Notes |
|
Source | extensions/hash/hash.lua line 41 |
Signature | hs.hash.SHA512(data) -> string |
---|---|
Type | Deprecated |
Description | Calculates an SHA512 hash |
Notes |
|
Source | extensions/hash/hash.lua line 54 |
Signature | hs.hash.types |
---|---|
Type | Constant |
Description | A tale containing the names of the hashing algorithms supported by this module. |
Notes | At present, this module supports the following hash functions:
|
Source | extensions/hash/hash.lua line 188 |
Signature | hs.hash.convertBinaryHashToHex(input) -> string |
---|---|
Type | Function |
Description | Converts a string containing a binary hash value to its equivalent hexadecimal digits. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/hash/hash.lua line 231 |
Signature | hs.hash.convertHexHashToBinary(input) -> string |
---|---|
Type | Function |
Description | Converts a string containing a hash value as a string of hexadecimal digits into its binary equivalent. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/hash/hash.lua line 210 |
Signature | hs.hash.forFile(hash, [secret], path) -> string |
---|---|
Type | Function |
Description | Calculates the specified hash value for the file at the given path. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/hash/hash.lua line 252 |
Signature | hs.hash.new(hash, [secret]) -> hashObject |
---|---|
Type | Constructor |
Description | Creates a new context for the specified hash function. |
Parameters |
|
Returns |
|
Source | extensions/hash/libhash.m line 86 |
Signature | hs.hash:append(data) -> hashObject | nil, error |
---|---|
Type | Method |
Description | Adds the provided data to the input of the hash function currently in progress for the hashObject. |
Parameters |
|
Returns |
|
Source | extensions/hash/libhash.m line 126 |
Signature | hs.hash:appendFile(path) -> hashObject | nil, error |
---|---|
Type | Method |
Description | Adds the contents of the file at the specified path to the input of the hash function currently in progress for the hashObject. |
Parameters |
|
Returns |
|
Source | extensions/hash/libhash.m line 154 |
Signature | hs.hash:finish() -> hashObject |
---|---|
Type | Method |
Description | Finalizes the hash and computes the resulting value. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/hash/libhash.m line 190 |
Signature | hs.hash:type() -> string |
---|---|
Type | Method |
Description | Returns the name of the hash type the object refers to |
Parameters |
|
Returns |
|
Source | extensions/hash/libhash.m line 246 |
Signature | hs.hash:value([binary]) -> string | nil |
---|---|
Type | Method |
Description | Returns the value of a completed hash, or nil if it is still in progress. |
Parameters |
|
Returns |
|
Source | extensions/hash/libhash.m line 213 |