Skip to content

SKeySizeSpec

Jay edited this page Oct 3, 2026 · 2 revisions

SKeySizeSpec

#include <certpp/crypto/keys.hpp> --- certpp::crypto

The valid key sizes for a cryptographic algorithm.

Fields

  • SKeySize minSize
  • SKeySize maxSize --- < Minimum key size in bits.
  • SKeySize step --- < Maximum key size in bits.

Methods

constexpr SKeySizeSpec()

Default constructor; all fields zero.

constexpr SKeySizeSpec(SKeySize size)

Constructs a spec accepting a single size.

  • size --- The key size in bits.

constexpr SKeySizeSpec(SKeySize minSize, SKeySize maxSize, SKeySize step)

  • minSize --- Minimum key size in bits.
  • maxSize --- Maximum key size in bits.
  • step --- Increment step for valid key sizes in bits.

inline bool empty() const

Returns: true if minSize, maxSize, and step are all zero.

inline operator bool() const

Returns: true if this specification is not empty.

inline bool operator!() const

Returns: true if this specification is empty.

inline bool includes(SKeySize size) const

Checks if a given key size is included in the valid key sizes.

  • size --- The key size in bits to check.

Returns: true if size is valid according to this specification.

int32_t compare(const SKeySizeSpec& other) const

  • other --- The other key size specification to compare with.

Returns: A negative value if this is less than other, zero if equal, positive if greater.

inline bool operator<(const SKeySizeSpec& other) const

Returns: true if this specification is less than the other specification.

inline bool operator<=(const SKeySizeSpec& other) const

Returns: true if this specification is less than or equal to the other specification.

inline bool operator>(const SKeySizeSpec& other) const

Returns: true if this specification is greater than the other specification.

inline bool operator>=(const SKeySizeSpec& other) const

Returns: true if this specification is greater than or equal to the other specification.

inline bool operator==(const SKeySizeSpec& other) const

Returns: true if this specification is equal to the other specification.

inline bool operator!=(const SKeySizeSpec& other) const

Returns: true if this specification is not equal to the other specification.

Example

Checks a caller-supplied key size against what the algorithm actually accepts, before generateKeyPair() rejects it. A spec built from one size has step 0 and includes() only that size; RSA's is a range with a step, so 2048 passes and 2049 does not.

// given: const crypto::IAsymmetricPtr& algo, crypto::SKeySize requested
bool accepted = false;
for (const crypto::SKeySizeSpec& spec : algo->keySizes()) {
    if (spec.includes(requested)) {
        accepted = true;
        break;
    }
}

if (!accepted) {
    return; // generateKeyPair() would answer ERET_KEY_SIZE
}

crypto::SKeyPair pair;
if (algo->generateKeyPair(requested, pair) != ERET_OK) {
    return;
}

Reference generated from certpp/crypto/keys.hpp at commit 0834b29 (v1.0.1). The header is authoritative --- if this page disagrees with it, the header is right and this page needs regenerating.

Clone this wiki locally