Skip to content

CGeneralSubtree

Jay edited this page Oct 3, 2026 · 2 revisions

CGeneralSubtree

#include <certpp/x509/generalname.hpp> --- certpp::x509

One GeneralSubtree (RFC 5280 4.2.1.10): a name (and, for hierarchical name forms, everything subordinate to it) a CA is permitted or excluded from certifying.

Methods

CGeneralSubtree() = default

Constructs an empty GeneralSubtree.

CGeneralSubtree(const CGeneralName& base, int64_t minimum, bool hasMaximum, int64_t maximum)

Constructs a GeneralSubtree from its decoded fields.

  • base --- The base name.
  • minimum --- The minimum distance (0 if absent, its DER default).
  • hasMaximum --- Whether a maximum distance is present.
  • maximum --- The maximum distance, if hasMaximum is true.

inline const CGeneralName& base() const

The base name this subtree is rooted at.

Returns: The base name.

inline int64_t minimum() const

The minimum distance below base() this constraint applies from (0, the DER default, if absent -- meaning it applies starting at base() itself).

RFC 5280 4.2.1.10 does not merely make a non-zero value rare, it forbids one: "within this profile, the minimum and maximum fields are not used with any name forms, thus minimum MUST be zero". A validator that honours a non-zero minimum narrows the subtree the constraint covers, which lets through exactly the names the constraint was there to exclude -- so a non-zero value here is grounds to reject the certificate, not to apply the offset.

Returns: The minimum distance, which a conforming certificate states as 0 or omits.

inline bool hasMaximum() const

Whether maximum() is present.

Returns: true if present.

inline int64_t maximum() const

The maximum distance below base() this constraint applies to. Only meaningful when hasMaximum() is true.

As with minimum(), RFC 5280 4.2.1.10 forbids the field outright -- "maximum MUST be absent" -- so hasMaximum() returning true is a non-conformance to reject rather than a bound to enforce. It is reported rather than dropped so the caller can see that the certificate carried it.

Returns: The maximum distance, meaningful only when hasMaximum() is true.

bool encode(CBuffer& out) const

Encodes this GeneralSubtree as its own SEQUENCE tag-length-value, the inverse of NameConstraints' decodeGeneralSubtrees(), appending it to out.

  • out --- The destination array; the encoded TLV is appended to whatever it already holds.

Returns: true on success; false if base() can't be encoded (see CGeneralName::encode()).

Example

One permitted or excluded name for a NameConstraints extension. minimum()/maximum() are essentially never used in practice -- pass 0 and false -- and a DNS subtree is written with a leading dot, which is what makes the constraint cover everything below the name.

// given: CCertBuilder& issuing
CNameConstraintsExtensionBuilder nc;
nc.addPermittedSubtree(
    CGeneralSubtree(CGeneralName(EGNAME_DNS, CString(".example.com")), 0, false, 0)
);
nc.addExcludedSubtree(
    CGeneralSubtree(CGeneralName(EGNAME_DNS, CString(".internal.example.com")), 0, false, 0)
);

IExtensionPtr ext = nc.build();
if (!ext) {
    return;
}

// RFC 5280 4.2.1.10 requires NameConstraints to be marked critical.
ext->critical(true);
issuing.extensions.add(ext);

Reference generated from certpp/x509/generalname.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