[*] Went over baseN and RSA again
This commit is contained in:
parent
c36f159f95
commit
6ac4fd61ab
@ -149,7 +149,7 @@ namespace Aurora::Crypto::RSA
|
||||
|
||||
AuSPtr<IRSAPublic> PrivateRSA::ToPublic()
|
||||
{
|
||||
rsa_key key;
|
||||
rsa_key key {};
|
||||
key.type = this->key_.type;
|
||||
|
||||
#define COPY_KEY_PART(x) \
|
||||
@ -206,7 +206,6 @@ namespace Aurora::Crypto::RSA
|
||||
|
||||
AUKN_SYM IRSAPrivate *NewRSAKeyNew(AuUInt16 keySize)
|
||||
{
|
||||
prng_state yarrow_prng {};
|
||||
rsa_key key {};
|
||||
const int prng_idx = register_prng(&sprng_desc);
|
||||
|
||||
|
@ -13,21 +13,28 @@ namespace Aurora::Parse
|
||||
{
|
||||
AUKN_SYM bool Base32Decode(const AuString &in, AuByteBuffer &decoded)
|
||||
{
|
||||
int iRet;
|
||||
unsigned long length = in.size();
|
||||
|
||||
auto writeView = decoded.GetOrAllocateLinearWriteable(length);
|
||||
if (!writeView)
|
||||
{
|
||||
SysPushErrorMem();
|
||||
return {};
|
||||
return false;
|
||||
}
|
||||
|
||||
iRet = ::base32_decode(AuReinterpretCast<const char *>(decoded.writePtr),
|
||||
(unsigned long)length,
|
||||
AuReinterpretCast<unsigned char *>(&decoded[0]),
|
||||
&length,
|
||||
BASE32_RFC4648);
|
||||
if (iRet != CRYPT_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto status = ::base32_decode(AuReinterpretCast<const char *>(decoded.writePtr),
|
||||
(unsigned long)length,
|
||||
AuReinterpretCast<unsigned char *>(&decoded[0]),
|
||||
&length, BASE32_RFC4648);
|
||||
decoded.writePtr += length;
|
||||
return status == CRYPT_OK;
|
||||
return true;
|
||||
}
|
||||
|
||||
AUKN_SYM bool Base32Encode(const void *buffer, AuMach length, AuString &encoded)
|
||||
@ -40,17 +47,18 @@ namespace Aurora::Parse
|
||||
return false;
|
||||
}
|
||||
|
||||
auto status = ::base32_encode(AuReinterpretCast<const unsigned char *>(buffer),
|
||||
(unsigned long)length,
|
||||
&encoded[0],
|
||||
&outLength,
|
||||
BASE32_RFC4648);
|
||||
if (!AuTryResize(encoded, length))
|
||||
auto iRet = ::base32_encode(AuReinterpretCast<const unsigned char *>(buffer),
|
||||
(unsigned long)length,
|
||||
&encoded[0],
|
||||
&outLength,
|
||||
BASE32_RFC4648);
|
||||
|
||||
if (!AuTryResize(encoded, outLength))
|
||||
{
|
||||
SysPushErrorMem();
|
||||
return false;
|
||||
}
|
||||
|
||||
return status == CRYPT_OK;
|
||||
return iRet == CRYPT_OK;
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ namespace Aurora::Parse
|
||||
{
|
||||
AUKN_SYM bool Base64Decode(const AuString &in, AuByteBuffer &decoded, bool url)
|
||||
{
|
||||
int iRet;
|
||||
unsigned long length = (unsigned long)in.size();
|
||||
|
||||
auto writeView = decoded.GetOrAllocateLinearWriteable(length);
|
||||
@ -22,28 +23,33 @@ namespace Aurora::Parse
|
||||
return {};
|
||||
}
|
||||
|
||||
int status;
|
||||
if (url)
|
||||
{
|
||||
status = ::base64url_decode(AuReinterpretCast<const char *>(decoded.writePtr),
|
||||
(unsigned long)length,
|
||||
AuReinterpretCast<unsigned char *>(&decoded[0]),
|
||||
&length);
|
||||
iRet = ::base64url_decode(AuReinterpretCast<const char *>(decoded.writePtr),
|
||||
(unsigned long)length,
|
||||
AuReinterpretCast<unsigned char *>(&decoded[0]),
|
||||
&length);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ::base64_decode(AuReinterpretCast<const char *>(decoded.writePtr),
|
||||
(unsigned long)length,
|
||||
AuReinterpretCast<unsigned char *>(&decoded[0]),
|
||||
&length);
|
||||
iRet = ::base64_decode(AuReinterpretCast<const char *>(decoded.writePtr),
|
||||
(unsigned long)length,
|
||||
AuReinterpretCast<unsigned char *>(&decoded[0]),
|
||||
&length);
|
||||
}
|
||||
|
||||
if (iRet != CRYPT_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
decoded.writePtr += length;
|
||||
return status == CRYPT_OK;
|
||||
return true;
|
||||
}
|
||||
|
||||
AUKN_SYM bool Base64Encode(const Memory::MemoryViewRead &input, AuString &encoded, bool url)
|
||||
{
|
||||
int iRet;
|
||||
unsigned long outLength = input.length + (input.length / 3.0) + 16;
|
||||
|
||||
if (!AuTryResize(encoded, outLength))
|
||||
@ -52,14 +58,19 @@ namespace Aurora::Parse
|
||||
return false;
|
||||
}
|
||||
|
||||
int status;
|
||||
if (url)
|
||||
{
|
||||
status = base64url_encode(reinterpret_cast<const unsigned char*>(input.ptr), (unsigned long)input.length, &encoded[0], &outLength);
|
||||
iRet = ::base64url_encode(AuReinterpretCast<const unsigned char*>(input.ptr),
|
||||
(unsigned long)input.length,
|
||||
&encoded[0],
|
||||
&outLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = base64_encode(reinterpret_cast<const unsigned char*>(input.ptr), (unsigned long)input.length, &encoded[0], &outLength);
|
||||
iRet =::base64_encode(AuReinterpretCast<const unsigned char*>(input.ptr),
|
||||
(unsigned long)input.length,
|
||||
&encoded[0],
|
||||
&outLength);
|
||||
}
|
||||
|
||||
if (!AuTryResize(encoded, outLength))
|
||||
@ -68,6 +79,6 @@ namespace Aurora::Parse
|
||||
return false;
|
||||
}
|
||||
|
||||
return status == CRYPT_OK;
|
||||
return iRet == CRYPT_OK;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user