Package org.microproxy.starlark.stdlib
Class HashlibModule
java.lang.Object
org.microproxy.starlark.stdlib.HashlibModule
- All Implemented Interfaces:
org.microproxy.thirdparty.starlark.eval.StarlarkValue
public final class HashlibModule
extends Object
implements org.microproxy.thirdparty.starlark.eval.StarlarkValue
@stdlib//jhashlib: the JDK's message digests and MACs for hashlib.star and
hmac.star (starlarky built these on BouncyCastle). BLAKE2 and SHAKE are not in the JDK and
are not available.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA hashlib hash object.static final classAn hmac HMAC object. -
Method Summary
Modifier and TypeMethodDescriptionorg.microproxy.thirdparty.starlark.eval.StarlarkList<String> algorithms(org.microproxy.thirdparty.starlark.eval.StarlarkThread thread) Lists the supported Python hash algorithm names in sorted order.booleancompareDigest(Object a, Object b) Compares like-typed byte strings or ASCII strings with the JDK digest comparison.hmac(Object key, Object msg, String digestmod, org.microproxy.thirdparty.starlark.eval.StarlarkThread thread) Creates a keyed HMAC object, optionally initialized with message bytes.Creates a hash object initialized with supplied bytes.org.microproxy.thirdparty.starlark.eval.StarlarkBytespbkdf2Hmac(String hashName, Object password, Object salt, org.microproxy.thirdparty.starlark.eval.StarlarkInt iterations, Object dklen, org.microproxy.thirdparty.starlark.eval.StarlarkThread thread) Derives a key using PBKDF2 with the requested HMAC digest.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.microproxy.thirdparty.starlark.eval.StarlarkValue
checkHashable, debugPrint, getStarlarkType, isAcyclic, isImmutable, repr, str, truth
-
Method Details
-
algorithms
public org.microproxy.thirdparty.starlark.eval.StarlarkList<String> algorithms(org.microproxy.thirdparty.starlark.eval.StarlarkThread thread) Lists the supported Python hash algorithm names in sorted order.- Parameters:
thread- the calling thread that owns the result list- Returns:
- the supported algorithm names
-
newHash
public HashlibModule.HashObject newHash(String name, Object data, org.microproxy.thirdparty.starlark.eval.StarlarkThread thread) throws org.microproxy.thirdparty.starlark.eval.EvalException Creates a hash object initialized with supplied bytes.- Parameters:
name- the Python hash algorithm namedata- the initial Starlark bytesthread- the calling thread that owns the hash object- Returns:
- a mutable hash object
- Throws:
org.microproxy.thirdparty.starlark.eval.EvalException- if the algorithm is unavailable or data is not bytes
-
hmac
public HashlibModule.HmacObject hmac(Object key, Object msg, String digestmod, org.microproxy.thirdparty.starlark.eval.StarlarkThread thread) throws org.microproxy.thirdparty.starlark.eval.EvalException Creates a keyed HMAC object, optionally initialized with message bytes.- Parameters:
key- the Starlark bytes used as the HMAC keymsg- the initial Starlark bytes, orNonefor an empty messagedigestmod- the Python digest algorithm namethread- the calling thread that owns the HMAC object- Returns:
- a mutable HMAC object
- Throws:
org.microproxy.thirdparty.starlark.eval.EvalException- if the algorithm or key is unsupported or an input is not bytes
-
compareDigest
public boolean compareDigest(Object a, Object b) throws org.microproxy.thirdparty.starlark.eval.EvalException Compares like-typed byte strings or ASCII strings with the JDK digest comparison.- Parameters:
a- the first Starlark bytes or ASCII stringb- the second value, of the same type asa- Returns:
- whether the byte representations are equal
- Throws:
org.microproxy.thirdparty.starlark.eval.EvalException- if the types differ, are unsupported or contain non-ASCII text
-
pbkdf2Hmac
public org.microproxy.thirdparty.starlark.eval.StarlarkBytes pbkdf2Hmac(String hashName, Object password, Object salt, org.microproxy.thirdparty.starlark.eval.StarlarkInt iterations, Object dklen, org.microproxy.thirdparty.starlark.eval.StarlarkThread thread) throws org.microproxy.thirdparty.starlark.eval.EvalException Derives a key using PBKDF2 with the requested HMAC digest.- Parameters:
hashName- the Python digest algorithm namepassword- the password as Starlark bytessalt- the salt as Starlark bytesiterations- the positive iteration countdklen- the positive key length in bytes, orNonefor the digest sizethread- the calling interpreter thread supplying ownership and the deadline- Returns:
- the derived key as immutable bytes
- Throws:
org.microproxy.thirdparty.starlark.eval.EvalException- if arguments are invalid, the digest is unsupported or the deadline expires
-