Function fromBytes [src]

Prototype

pub fn fromBytes(pub_bytes: []const u8, modulus_bytes: []const u8) FromBytesError!PublicKey

Parameters

pub_bytes: []const u8modulus_bytes: []const u8

Possible Errors

CertificatePublicKeyInvalid

Source

pub fn fromBytes(pub_bytes: []const u8, modulus_bytes: []const u8) 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) catch return error.CertificatePublicKeyInvalid; if (_n.bits() < 512) return error.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-rsapubkey if (pub_bytes.len > 4) return error.CertificatePublicKeyInvalid; const _e = Fe.fromBytes(_n, pub_bytes, .big) catch return error.CertificatePublicKeyInvalid; if (!_e.isOdd()) return error.CertificatePublicKeyInvalid; const e_v = _e.toPrimitive(u32) catch return error.CertificatePublicKeyInvalid; if (e_v < 2) return error.CertificatePublicKeyInvalid; return .{ .n = _n, .e = _e, }; }