feature. See also
. The project being documented here (as the example) is the Zig library itself.
Certificate.verifyRsa
fn verifyRsa(
comptime Hash: type,
msg: []const u8,
sig: []const u8,
pub_key_algo: Parsed.PubKeyAlgo,
pub_key: []const u8,
) !void
File
Code
fn verifyRsa(
comptime Hash: type,
msg: []const u8,
sig: []const u8,
pub_key_algo: Parsed.PubKeyAlgo,
pub_key: []const u8,
) !void {
if (pub_key_algo != .rsaEncryption) return error.CertificateSignatureAlgorithmMismatch;
const pk_components = try rsa.PublicKey.parseDer(pub_key);
const exponent = pk_components.exponent;
const modulus = pk_components.modulus;
if (exponent.len > modulus.len) return error.CertificatePublicKeyInvalid;
if (sig.len != modulus.len) return error.CertificateSignatureInvalidLength;
switch (modulus.len) {
inline 128, 256, 384, 512 => |modulus_len| {
const public_key = rsa.PublicKey.fromBytes(exponent, modulus) catch
return error.CertificateSignatureInvalid;
rsa.PKCS1v1_5Signature.verify(modulus_len, sig[0..modulus_len].*, msg, public_key, Hash) catch
return error.CertificateSignatureInvalid;
},
else => return error.CertificateSignatureUnsupportedBitCount,
}
}