mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 08:18:12 +00:00
AK: Rename span() to bytes() when appropriate.
I originally defined the bytes() method for the String class, because it made it obvious that it's a span of bytes instead of span of characters. This commit makes this more consistent by defining a bytes() method when the type of the span is known to be u8. Additionaly, the cast operator to Bytes is overloaded for ByteBuffer and such.
This commit is contained in:
parent
525d51bbb5
commit
fff581cd72
18 changed files with 51 additions and 45 deletions
|
@ -125,7 +125,7 @@ void RSA::encrypt(const ByteBuffer& in, ByteBuffer& out)
|
|||
return;
|
||||
}
|
||||
auto exp = NumberTheory::ModularPower(in_integer, m_public_key.public_exponent(), m_public_key.modulus());
|
||||
auto size = exp.export_data(out.span());
|
||||
auto size = exp.export_data(out);
|
||||
auto outsize = out.size();
|
||||
if (size != outsize) {
|
||||
dbg() << "POSSIBLE RSA BUG!!! Size mismatch: " << outsize << " requested but " << size << " bytes generated";
|
||||
|
@ -139,7 +139,7 @@ void RSA::decrypt(const ByteBuffer& in, ByteBuffer& out)
|
|||
|
||||
auto in_integer = UnsignedBigInteger::import_data(in.data(), in.size());
|
||||
auto exp = NumberTheory::ModularPower(in_integer, m_private_key.private_exponent(), m_private_key.modulus());
|
||||
auto size = exp.export_data(out.span());
|
||||
auto size = exp.export_data(out);
|
||||
|
||||
auto align = m_private_key.length();
|
||||
auto aligned_size = (size + align - 1) / align * align;
|
||||
|
@ -153,7 +153,7 @@ void RSA::sign(const ByteBuffer& in, ByteBuffer& out)
|
|||
{
|
||||
auto in_integer = UnsignedBigInteger::import_data(in.data(), in.size());
|
||||
auto exp = NumberTheory::ModularPower(in_integer, m_private_key.private_exponent(), m_private_key.modulus());
|
||||
auto size = exp.export_data(out.span());
|
||||
auto size = exp.export_data(out);
|
||||
out = out.slice(out.size() - size, size);
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ void RSA::verify(const ByteBuffer& in, ByteBuffer& out)
|
|||
{
|
||||
auto in_integer = UnsignedBigInteger::import_data(in.data(), in.size());
|
||||
auto exp = NumberTheory::ModularPower(in_integer, m_public_key.public_exponent(), m_public_key.modulus());
|
||||
auto size = exp.export_data(out.span());
|
||||
auto size = exp.export_data(out);
|
||||
out = out.slice(out.size() - size, size);
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ void RSA::import_private_key(ReadonlyBytes bytes, bool pem)
|
|||
ByteBuffer buffer;
|
||||
if (pem) {
|
||||
buffer = decode_pem(bytes);
|
||||
bytes = buffer.span();
|
||||
bytes = buffer;
|
||||
}
|
||||
|
||||
auto key = parse_rsa_key(bytes);
|
||||
|
@ -186,7 +186,7 @@ void RSA::import_public_key(ReadonlyBytes bytes, bool pem)
|
|||
ByteBuffer buffer;
|
||||
if (pem) {
|
||||
buffer = decode_pem(bytes);
|
||||
bytes = buffer.span();
|
||||
bytes = buffer;
|
||||
}
|
||||
|
||||
auto key = parse_rsa_key(bytes);
|
||||
|
|
|
@ -160,8 +160,8 @@ public:
|
|||
|
||||
RSA(const ByteBuffer& publicKeyPEM, const ByteBuffer& privateKeyPEM)
|
||||
{
|
||||
import_public_key(publicKeyPEM.span());
|
||||
import_private_key(privateKeyPEM.span());
|
||||
import_public_key(publicKeyPEM);
|
||||
import_private_key(privateKeyPEM);
|
||||
}
|
||||
|
||||
RSA(const StringView& privKeyPEM)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue