This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function
pubfnfromBytes(pub_bytes: []constu8, modulus_bytes: []constu8) FromBytesError!PublicKey {
// Reject modulus below 512 bits.// 512-bit RSA was factored in 1999, so this limit barely means anything,// but establish some limit now to ratchet in what we can.const_n = Modulus.fromBytes(modulus_bytes, .big) catchreturnerror.CertificatePublicKeyInvalid;
if (_n.bits() < 512) returnerror.CertificatePublicKeyInvalid;
// Exponent must be odd and greater than 2.// Also, it must be less than 2^32 to mitigate DoS attacks.// Windows CryptoAPI doesn't support values larger than 32 bits [1], so it is// unlikely that exponents larger than 32 bits are being used for anything// Windows commonly does.// [1] https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/ns-wincrypt-rsapubkeyif (pub_bytes.len > 4) returnerror.CertificatePublicKeyInvalid;
const_e = Fe.fromBytes(_n, pub_bytes, .big) catchreturnerror.CertificatePublicKeyInvalid;
if (!_e.isOdd()) returnerror.CertificatePublicKeyInvalid;
conste_v = _e.toPrimitive(u32) catchreturnerror.CertificatePublicKeyInvalid;
if (e_v < 2) returnerror.CertificatePublicKeyInvalid;
return .{
.n = _n,
.e = _e,
};
}