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 Classes
    Modifier and Type
    Class
    Description
    static final class 
    A hashlib hash object.
    static final class 
    An hmac HMAC object.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    boolean
    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.
    newHash(String name, Object data, org.microproxy.thirdparty.starlark.eval.StarlarkThread thread)
    Creates a hash object initialized with supplied bytes.
    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)
    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, wait

    Methods 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 name
      data - the initial Starlark bytes
      thread - 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 key
      msg - the initial Starlark bytes, or None for an empty message
      digestmod - the Python digest algorithm name
      thread - 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 string
      b - the second value, of the same type as a
      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 name
      password - the password as Starlark bytes
      salt - the salt as Starlark bytes
      iterations - the positive iteration count
      dklen - the positive key length in bytes, or None for the digest size
      thread - 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