<commit_before>#!/usr/bin/env python

"""
<Program Name>
  formats.py

<Author>
  <NAME>
  <NAME> <<EMAIL>>

<Started>
  Refactored April 30, 2012. -vladimir.v.diaz

<Copyright>
  2008-2011 The Tor Project, Inc
  2012-2016 New York University and the TUF contributors
  2016-2021 Securesystemslib contributors
  See LICENSE for licensing information.

<Purpose>
  A central location for all format-related checking of securesystemslib
  objects. Note: 'formats.py' depends heavily on 'schema.py', so the
  'schema.py' module should be read and understood before tackling this module.

  'formats.py' can be broken down into three sections.  (1) Schemas and object
  matching.  (2) Classes that represent Role Metadata and help produce
  correctly formatted files.  (3) Functions that help produce or verify
  securesystemslib objects.

  The first section deals with schemas and object matching based on format.
  There are two ways of checking the format of objects.  The first method
  raises a 'securesystemslib.exceptions.FormatError' exception if the match
  fails and the other returns a Boolean result.

  securesystemslib.formats.<SCHEMA>.check_match(object)
  securesystemslib.formats.<SCHEMA>.matches(object)

  Example:

  rsa_key = {'keytype': 'rsa'
             'keyid': <KEY>
             'keyval': {'public': 'public_key',
                        'private': 'private_key'}

  securesystemslib.formats.RSAKEY_SCHEMA.check_match(rsa_key)
  securesystemslib.formats.RSAKEY_SCHEMA.matches(rsa_key)

  In this example, if a dict key or dict value is missing or incorrect,
  the match fails.  There are numerous variations of object checking
  provided by 'formats.py' and 'schema.py'.

  The second section deals with the role metadata classes.  There are
  multiple top-level roles, each with differing metadata formats.
  Example:

  root_object = securesystemslib.formats.RootFile.from_metadata(root_metadata_file)
  targets_metadata = securesystemslib.formats.TargetsFile.make_metadata(...)

  The input and output of these classes are checked against their respective
  schema to ensure correctly formatted metadata.

  The last section contains miscellaneous functions related to the format of
  securesystemslib objects.
  Example:

  signable_object = make_signable(unsigned_object)
"""

import binascii
import calendar
import datetime
import time

from securesystemslib import exceptions
from securesystemslib import schema as SCHEMA

# Note that in the schema definitions below, the 'SCHEMA.Object' types allow
# additional keys which are not defined. Thus, any additions to them will be
# easily backwards compatible with clients that are already deployed.

ANY_STRING_SCHEMA = SCHEMA.AnyString()
LIST_OF_ANY_STRING_SCHEMA = SCHEMA.ListOf(ANY_STRING_SCHEMA)

# A datetime in 'YYYY-MM-DDTHH:MM:SSZ' ISO 8601 format.  The "Z" zone designator
# for the zero UTC offset is always used (i.e., a numerical offset is not
# supported.)  Example: '2015-10-21T13:20:00Z'.  Note:  This is a simple format
# check, and an ISO8601 string should be fully verified when it is parsed.
ISO8601_DATETIME_SCHEMA = SCHEMA.RegularExpression(
    r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z"
)

# A Unix/POSIX time format.  An integer representing the number of seconds
# since the epoch (January 1, 1970.)  Metadata uses this format for the
# 'expires' field.  Set 'hi' to the upper timestamp limit (year 2038), the max
# value of an int.
UNIX_TIMESTAMP_SCHEMA = SCHEMA.Integer(lo=0, hi=2147483647)

# A hexadecimal value in '23432df87ab..' format.
HEX_SCHEMA = SCHEMA.RegularExpression(r"[a-fA-F0-9]+")

HASH_SCHEMA = HEX_SCHEMA

# A dict in {'sha256': '23432df87ab..', 'sha512': '34324abc34df..', ...} format.
HASHDICT_SCHEMA = SCHEMA.DictOf(
    key_schema=SCHEMA.AnyString(), value_schema=HASH_SCHEMA
)

# Uniform Resource Locator identifier (e.g., 'https://www.updateframework.com/').
# TODO: Some level of restriction here would be good....  Note that I pulled
#       this from securesystemslib, since it's neither sophisticated nor used
#       by anyone else.
URL_SCHEMA = SCHEMA.AnyString()

# A key identifier (e.g., a hexadecimal value identifying an RSA key).
KEYID_SCHEMA = HASH_SCHEMA

# A list of KEYID_SCHEMA.
KEYIDS_SCHEMA = SCHEMA.ListOf(KEYID_SCHEMA)

# The signing scheme used by a key to generate a signature (e.g.,
# 'rsassa-pss-sha256' is one of the signing schemes for key type 'rsa').
SCHEME_SCHEMA = SCHEMA.AnyString()

# A path string, whether relative or absolute, e.g. 'metadata/root/'
PATH_SCHEMA = SCHEMA.AnyNonemptyString()
PATHS_SCHEMA = SCHEMA.ListOf(PATH_SCHEMA)

# An integer representing logger levels, such as logging.CRITICAL (=50).
# Must be between 0 and 50.
LOGLEVEL_SCHEMA = SCHEMA.Integer(lo=0, hi=50)

# A string representing a named object.
NAME_SCHEMA = SCHEMA.AnyString()
NAMES_SCHEMA = SCHEMA.ListOf(NAME_SCHEMA)

# A byte string representing data.
DATA_SCHEMA = SCHEMA.AnyBytes()

# A text string.  For instance, a string entered by the user.
TEXT_SCHEMA = SCHEMA.AnyString()

# Supported hash algorithms.
HASHALGORITHMS_SCHEMA = SCHEMA.ListOf(
    SCHEMA.OneOf(
        [
            SCHEMA.String("md5"),
            SCHEMA.String("sha1"),
            SCHEMA.String("sha224"),
            SCHEMA.String("sha256"),
            SCHEMA.String("sha384"),
            SCHEMA.String("sha512"),
            SCHEMA.String("blake2s"),
            SCHEMA.String("blake2b"),
            SCHEMA.String("blake2b-256"),
        ]
    )
)

# The contents of an encrypted key.  Encrypted keys are saved to files
# in this format.
ENCRYPTEDKEY_SCHEMA = SCHEMA.AnyString()

# A value that is either True or False, on or off, etc.
BOOLEAN_SCHEMA = SCHEMA.Boolean()

# The minimum number of bits for an RSA key.  Must be 2048 bits, or greater
# (recommended by TUF).  Recommended RSA key sizes:
# http://www.emc.com/emc-plus/rsa-labs/historical/twirl-and-rsa-key-size.htm#table1
RSAKEYBITS_SCHEMA = SCHEMA.Integer(lo=2048)

# The supported ECDSA signature schemes
ECDSA_SCHEME_SCHEMA = SCHEMA.RegularExpression(r"ecdsa-sha2-nistp(256|384)")

# A pyca-cryptography signature.
PYCACRYPTOSIGNATURE_SCHEMA = SCHEMA.AnyBytes()

# An RSA key in PEM format.
PEMRSA_SCHEMA = SCHEMA.AnyString()

# An ECDSA key in PEM format.
PEMECDSA_SCHEMA = SCHEMA.AnyString()

# A string representing a password.
PASSWORD_SCHEMA = SCHEMA.AnyString()

# A list of passwords.
PASSWORDS_SCHEMA = SCHEMA.ListOf(PASSWORD_SCHEMA)

# The actual values of a key, as opposed to meta data such as a key type and
# key identifier ('rsa', 233df889cb).  For RSA keys, the key value is a pair of
# public and private keys in PEM Format stored as strings.
KEYVAL_SCHEMA = SCHEMA.Object(
    object_name="KEYVAL_SCHEMA",
    public=SCHEMA.AnyString(),
    private=SCHEMA.Optional(SCHEMA.AnyString()),
)

# Public keys CAN have a private portion (for backwards compatibility) which
# MUST be an empty string
PUBLIC_KEYVAL_SCHEMA = SCHEMA.Object(
    object_name="KEYVAL_SCHEMA",
    public=SCHEMA.AnyString(),
    private=SCHEMA.Optional(SCHEMA.String("")),
)

# Supported securesystemslib key types.
KEYTYPE_SCHEMA = SCHEMA.OneOf(
    [
        SCHEMA.String("rsa"),
        SCHEMA.String("ed25519"),
        SCHEMA.String("ecdsa"),
        SCHEMA.RegularExpression(r"ecdsa-sha2-nistp(256|384)"),
        SCHEMA.String('sphincs-shake-128s')
    ]
)

# A generic securesystemslib key.  All securesystemslib keys should be saved to
# metadata files in this format.
KEY_SCHEMA = SCHEMA.Object(
    object_name="KEY_SCHEMA",
    keytype=SCHEMA.AnyString(),
    scheme=SCHEME_SCHEMA,
    keyval=KEYVAL_SCHEMA,
    expires=SCHEMA.Optional(ISO8601_DATETIME_SCHEMA),
)

# Like KEY_SCHEMA, but requires keyval's private portion to be unset or empty,
# and optionally includes the supported keyid hash algorithms used to generate
# the key's keyid.
PUBLIC_KEY_SCHEMA = SCHEMA.Object(
    object_name="PUBLIC_KEY_SCHEMA",
    keytype=SCHEMA.AnyString(),
    keyid_hash_algorithms=SCHEMA.Optional(HASHALGORITHMS_SCHEMA),
    keyval=PUBLIC_KEYVAL_SCHEMA,
    expires=SCHEMA.Optional(ISO8601_DATETIME_SCHEMA),
)

# A securesystemslib key object.  This schema simplifies validation of keys
# that may be one of the supported key types.  Supported key types: 'rsa',
# 'ed25519'.
ANYKEY_SCHEMA = SCHEMA.Object(
    object_name="ANYKEY_SCHEMA",
    keytype=KEYTYPE_SCHEMA,
    scheme=SCHEME_SCHEMA,
    keyid=KEYID_SCHEMA,
    keyid_hash_algorithms=SCHEMA.Optional(HASHALGORITHMS_SCHEMA),
    keyval=KEYVAL_SCHEMA,
    expires=SCHEMA.Optional(ISO8601_DATETIME_SCHEMA),
)

# A list of securesystemslib key objects.
ANYKEYLIST_SCHEMA = SCHEMA.ListOf(ANYKEY_SCHEMA)

# RSA signature schemes.
RSA_SCHEME_SCHEMA = SCHEMA.OneOf(
    [
        SCHEMA.RegularExpression(
            r"rsassa-pss-(md5|sha1|sha224|sha256|sha384|sha512)"
        ),
        SCHEMA.RegularExpression(
            r"rsa-pkcs1v15-(md5|sha1|sha224|sha256|sha384|sha512)"
        ),
    ]
)

# An RSA securesystemslib key.
RSAKEY_SCHEMA = SCHEMA.Object(
    object_name="RSAKEY_SCHEMA",
    keytype=SCHEMA.String("rsa"),
    scheme=RSA_SCHEME_SCHEMA,
    keyid=KEYID_SCHEMA,
    keyid_hash_algorithms=SCHEMA.Optional(HASHALGORITHMS_SCHEMA),
    keyval=KEYVAL_SCHEMA,
)

# An ECDSA securesystemslib key.
ECDSAKEY_SCHEMA = SCHEMA.Object(
    object_name="ECDSAKEY_SCHEMA",
    keytype=SCHEMA.OneOf(
        [
            SCHEMA.String("ecdsa"),
            SCHEMA.RegularExpression(r"ecdsa-sha2-nistp(256|384)"),
        ]
    ),
    scheme=ECDSA_SCHEME_SCHEMA,
    keyid=KEYID_SCHEMA,
    keyid_hash_algorithms=SCHEMA.Optional(HASHALGORITHMS_SCHEMA),
    keyval=KEYVAL_SCHEMA,
)

# An ED25519 raw public key, which must be 32 bytes.
ED25519PUBLIC_SCHEMA = SCHEMA.LengthBytes(32)

# An SPHINCS raw public key, which must be 32 bytes.
SPHINCSPUBLIC_SCHEMA = SCHEMA.LengthBytes(32)

# An ED25519 raw seed key, which must be 32 bytes.
ED25519SEED_SCHEMA = SCHEMA.LengthBytes(32)

# An SPHINCS raw public key, which must be 32 bytes.
SPHINCSPRIVATE_SCHEMA = SCHEMA.LengthBytes(64)

# An ED25519 raw signature, which must be 64 bytes.
ED25519SIGNATURE_SCHEMA = SCHEMA.LengthBytes(64)

# An SPHINCS raw signature, which must be 64 bytes.
SPHINCSSIGNATURE_SCHEMA = SCHEMA.LengthBytes(7_856)

# An ECDSA signature.
ECDSASIGNATURE_SCHEMA = SCHEMA.AnyBytes()

# Ed25519 signature schemes.  The vanilla Ed25519 signature scheme is currently
# supported.
ED25519_SIG_SCHEMA = SCHEMA.OneOf([SCHEMA.String("ed25519")])<commit_msg>Remove comments over SPHINCS schema definitions as schemas should be self explanatory<commit_after>#!/usr/bin/env python

"""
<Program Name>
  formats.py

<Author>
  <NAME>
  <NAME> <<EMAIL>>

<Started>
  Refactored April 30, 2012. -vladimir.v.diaz

<Copyright>
  2008-2011 The Tor Project, Inc
  2012-2016 New York University and the TUF contributors
  2016-2021 Securesystemslib contributors
  See LICENSE for licensing information.

<Purpose>
  A central location for all format-related checking of securesystemslib
  objects. Note: 'formats.py' depends heavily on 'schema.py', so the
  'schema.py' module should be read and understood before tackling this module.

  'formats.py' can be broken down into three sections.  (1) Schemas and object
  matching.  (2) Classes that represent Role Metadata and help produce
  correctly formatted files.  (3) Functions that help produce or verify
  securesystemslib objects.

  The first section deals with schemas and object matching based on format.
  There are two ways of checking the format of objects.  The first method
  raises a 'securesystemslib.exceptions.FormatError' exception if the match
  fails and the other returns a Boolean result.

  securesystemslib.formats.<SCHEMA>.check_match(object)
  securesystemslib.formats.<SCHEMA>.matches(object)

  Example:

  rsa_key = {'keytype': 'rsa'
             'keyid': <KEY>
             'keyval': {'public': 'public_key',
                        'private': 'private_key'}

  securesystemslib.formats.RSAKEY_SCHEMA.check_match(rsa_key)
  securesystemslib.formats.RSAKEY_SCHEMA.matches(rsa_key)

  In this example, if a dict key or dict value is missing or incorrect,
  the match fails.  There are numerous variations of object checking
  provided by 'formats.py' and 'schema.py'.

  The second section deals with the role metadata classes.  There are
  multiple top-level roles, each with differing metadata formats.
  Example:

  root_object = securesystemslib.formats.RootFile.from_metadata(root_metadata_file)
  targets_metadata = securesystemslib.formats.TargetsFile.make_metadata(...)

  The input and output of these classes are checked against their respective
  schema to ensure correctly formatted metadata.

  The last section contains miscellaneous functions related to the format of
  securesystemslib objects.
  Example:

  signable_object = make_signable(unsigned_object)
"""

import binascii
import calendar
import datetime
import time

from securesystemslib import exceptions
from securesystemslib import schema as SCHEMA

# Note that in the schema definitions below, the 'SCHEMA.Object' types allow
# additional keys which are not defined. Thus, any additions to them will be
# easily backwards compatible with clients that are already deployed.

ANY_STRING_SCHEMA = SCHEMA.AnyString()
LIST_OF_ANY_STRING_SCHEMA = SCHEMA.ListOf(ANY_STRING_SCHEMA)

# A datetime in 'YYYY-MM-DDTHH:MM:SSZ' ISO 8601 format.  The "Z" zone designator
# for the zero UTC offset is always used (i.e., a numerical offset is not
# supported.)  Example: '2015-10-21T13:20:00Z'.  Note:  This is a simple format
# check, and an ISO8601 string should be fully verified when it is parsed.
ISO8601_DATETIME_SCHEMA = SCHEMA.RegularExpression(
    r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z"
)

# A Unix/POSIX time format.  An integer representing the number of seconds
# since the epoch (January 1, 1970.)  Metadata uses this format for the
# 'expires' field.  Set 'hi' to the upper timestamp limit (year 2038), the max
# value of an int.
UNIX_TIMESTAMP_SCHEMA = SCHEMA.Integer(lo=0, hi=2147483647)

# A hexadecimal value in '23432df87ab..' format.
HEX_SCHEMA = SCHEMA.RegularExpression(r"[a-fA-F0-9]+")

HASH_SCHEMA = HEX_SCHEMA

# A dict in {'sha256': '23432df87ab..', 'sha512': '34324abc34df..', ...} format.
HASHDICT_SCHEMA = SCHEMA.DictOf(
    key_schema=SCHEMA.AnyString(), value_schema=HASH_SCHEMA
)

# Uniform Resource Locator identifier (e.g., 'https://www.updateframework.com/').
# TODO: Some level of restriction here would be good....  Note that I pulled
#       this from securesystemslib, since it's neither sophisticated nor used
#       by anyone else.
URL_SCHEMA = SCHEMA.AnyString()

# A key identifier (e.g., a hexadecimal value identifying an RSA key).
KEYID_SCHEMA = HASH_SCHEMA

# A list of KEYID_SCHEMA.
KEYIDS_SCHEMA = SCHEMA.ListOf(KEYID_SCHEMA)

# The signing scheme used by a key to generate a signature (e.g.,
# 'rsassa-pss-sha256' is one of the signing schemes for key type 'rsa').
SCHEME_SCHEMA = SCHEMA.AnyString()

# A path string, whether relative or absolute, e.g. 'metadata/root/'
PATH_SCHEMA = SCHEMA.AnyNonemptyString()
PATHS_SCHEMA = SCHEMA.ListOf(PATH_SCHEMA)

# An integer representing logger levels, such as logging.CRITICAL (=50).
# Must be between 0 and 50.
LOGLEVEL_SCHEMA = SCHEMA.Integer(lo=0, hi=50)

# A string representing a named object.
NAME_SCHEMA = SCHEMA.AnyString()
NAMES_SCHEMA = SCHEMA.ListOf(NAME_SCHEMA)

# A byte string representing data.
DATA_SCHEMA = SCHEMA.AnyBytes()

# A text string.  For instance, a string entered by the user.
TEXT_SCHEMA = SCHEMA.AnyString()

# Supported hash algorithms.
HASHALGORITHMS_SCHEMA = SCHEMA.ListOf(
    SCHEMA.OneOf(
        [
            SCHEMA.String("md5"),
            SCHEMA.String("sha1"),
            SCHEMA.String("sha224"),
            SCHEMA.String("sha256"),
            SCHEMA.String("sha384"),
            SCHEMA.String("sha512"),
            SCHEMA.String("blake2s"),
            SCHEMA.String("blake2b"),
            SCHEMA.String("blake2b-256"),
        ]
    )
)

# The contents of an encrypted key.  Encrypted keys are saved to files
# in this format.
ENCRYPTEDKEY_SCHEMA = SCHEMA.AnyString()

# A value that is either True or False, on or off, etc.
BOOLEAN_SCHEMA = SCHEMA.Boolean()

# The minimum number of bits for an RSA key.  Must be 2048 bits, or greater
# (recommended by TUF).  Recommended RSA key sizes:
# http://www.emc.com/emc-plus/rsa-labs/historical/twirl-and-rsa-key-size.htm#table1
RSAKEYBITS_SCHEMA = SCHEMA.Integer(lo=2048)

# The supported ECDSA signature schemes
ECDSA_SCHEME_SCHEMA = SCHEMA.RegularExpression(r"ecdsa-sha2-nistp(256|384)")

# A pyca-cryptography signature.
PYCACRYPTOSIGNATURE_SCHEMA = SCHEMA.AnyBytes()

# An RSA key in PEM format.
PEMRSA_SCHEMA = SCHEMA.AnyString()

# An ECDSA key in PEM format.
PEMECDSA_SCHEMA = SCHEMA.AnyString()

# A string representing a password.
PASSWORD_SCHEMA = SCHEMA.AnyString()

# A list of passwords.
PASSWORDS_SCHEMA = SCHEMA.ListOf(PASSWORD_SCHEMA)

# The actual values of a key, as opposed to meta data such as a key type and
# key identifier ('rsa', 233df889cb).  For RSA keys, the key value is a pair of
# public and private keys in PEM Format stored as strings.
KEYVAL_SCHEMA = SCHEMA.Object(
    object_name="KEYVAL_SCHEMA",
    public=SCHEMA.AnyString(),
    private=SCHEMA.Optional(SCHEMA.AnyString()),
)

# Public keys CAN have a private portion (for backwards compatibility) which
# MUST be an empty string
PUBLIC_KEYVAL_SCHEMA = SCHEMA.Object(
    object_name="KEYVAL_SCHEMA",
    public=SCHEMA.AnyString(),
    private=SCHEMA.Optional(SCHEMA.String("")),
)

# Supported securesystemslib key types.
KEYTYPE_SCHEMA = SCHEMA.OneOf(
    [
        SCHEMA.String("rsa"),
        SCHEMA.String("ed25519"),
        SCHEMA.String("ecdsa"),
        SCHEMA.RegularExpression(r"ecdsa-sha2-nistp(256|384)"),
        SCHEMA.String('sphincs-shake-128s')
    ]
)

# A generic securesystemslib key.  All securesystemslib keys should be saved to
# metadata files in this format.
KEY_SCHEMA = SCHEMA.Object(
    object_name="KEY_SCHEMA",
    keytype=SCHEMA.AnyString(),
    scheme=SCHEME_SCHEMA,
    keyval=KEYVAL_SCHEMA,
    expires=SCHEMA.Optional(ISO8601_DATETIME_SCHEMA),
)

# Like KEY_SCHEMA, but requires keyval's private portion to be unset or empty,
# and optionally includes the supported keyid hash algorithms used to generate
# the key's keyid.
PUBLIC_KEY_SCHEMA = SCHEMA.Object(
    object_name="PUBLIC_KEY_SCHEMA",
    keytype=SCHEMA.AnyString(),
    keyid_hash_algorithms=SCHEMA.Optional(HASHALGORITHMS_SCHEMA),
    keyval=PUBLIC_KEYVAL_SCHEMA,
    expires=SCHEMA.Optional(ISO8601_DATETIME_SCHEMA),
)

# A securesystemslib key object.  This schema simplifies validation of keys
# that may be one of the supported key types.  Supported key types: 'rsa',
# 'ed25519'.
ANYKEY_SCHEMA = SCHEMA.Object(
    object_name="ANYKEY_SCHEMA",
    keytype=KEYTYPE_SCHEMA,
    scheme=SCHEME_SCHEMA,
    keyid=KEYID_SCHEMA,
    keyid_hash_algorithms=SCHEMA.Optional(HASHALGORITHMS_SCHEMA),
    keyval=KEYVAL_SCHEMA,
    expires=SCHEMA.Optional(ISO8601_DATETIME_SCHEMA),
)

# A list of securesystemslib key objects.
ANYKEYLIST_SCHEMA = SCHEMA.ListOf(ANYKEY_SCHEMA)

# RSA signature schemes.
RSA_SCHEME_SCHEMA = SCHEMA.OneOf(
    [
        SCHEMA.RegularExpression(
            r"rsassa-pss-(md5|sha1|sha224|sha256|sha384|sha512)"
        ),
        SCHEMA.RegularExpression(
            r"rsa-pkcs1v15-(md5|sha1|sha224|sha256|sha384|sha512)"
        ),
    ]
)

# An RSA securesystemslib key.
RSAKEY_SCHEMA = SCHEMA.Object(
    object_name="RSAKEY_SCHEMA",
    keytype=SCHEMA.String("rsa"),
    scheme=RSA_SCHEME_SCHEMA,
    keyid=KEYID_SCHEMA,
    keyid_hash_algorithms=SCHEMA.Optional(HASHALGORITHMS_SCHEMA),
    keyval=KEYVAL_SCHEMA,
)

# An ECDSA securesystemslib key.
ECDSAKEY_SCHEMA = SCHEMA.Object(
    object_name="ECDSAKEY_SCHEMA",
    keytype=SCHEMA.OneOf(
        [
            SCHEMA.String("ecdsa"),
            SCHEMA.RegularExpression(r"ecdsa-sha2-nistp(256|384)"),
        ]
    ),
    scheme=ECDSA_SCHEME_SCHEMA,
    keyid=KEYID_SCHEMA,
    keyid_hash_algorithms=SCHEMA.Optional(HASHALGORITHMS_SCHEMA),
    keyval=KEYVAL_SCHEMA,
)

# An ED25519 raw public key, which must be 32 bytes.
ED25519PUBLIC_SCHEMA = SCHEMA.LengthBytes(32)

SPHINCSPUBLIC_SCHEMA = SCHEMA.LengthBytes(32)

# An ED25519 raw seed key, which must be 32 bytes.
ED25519SEED_SCHEMA = SCHEMA.LengthBytes(32)

SPHINCSPRIVATE_SCHEMA = SCHEMA.LengthBytes(64)

# An ED25519 raw signature, which must be 64 bytes.
ED25519SIGNATURE_SCHEMA = SCHEMA.LengthBytes(64)

SPHINCSSIGNATURE_SCHEMA = SCHEMA.LengthBytes(7_856)

# An ECDSA signature.
ECDSASIGNATURE_SCHEMA = SCHEMA.AnyBytes()

# Ed25519 signature schemes.  The vanilla Ed25519 signature scheme is currently
# supported.
ED25519_SIG_SCHEMA = SCHEMA.OneOf([SCHEMA.String("ed25519")])
{'fraction_non_alphanumeric': 0.09331476323119778, 'fraction_numerical': 0.029776198251849007, 'mean_word_length': 4.130081300813008, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1434209', 'n_tokens_mistral': 7803, 'n_tokens_neox': 7279, 'n_words': 1903}