-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial standard library cryptography module source file implementation.
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2024 - Nathanne Isip | ||
* This file is part of N8. | ||
* | ||
* N8 is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, | ||
* or (at your option) any later version. | ||
* | ||
* N8 is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with N8. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "n8std/Crypt.hpp" | ||
|
||
#include <n8/ast/TerminativeSignal.hpp> | ||
|
||
#include <quickdigest5.hpp> | ||
#include <regex> | ||
|
||
N8_FUNC(crypt_md5) { | ||
if(args.size() != 1) | ||
throw TerminativeThrowSignal( | ||
std::move(address), | ||
"Expecting 1 argument, got " + | ||
std::to_string(args.size()) | ||
); | ||
|
||
DynamicObject input = args.at(0); | ||
return DynamicObject( | ||
QuickDigest5::toHash(input.toString()) | ||
); | ||
} | ||
|
||
N8_FUNC(crypt_validateMd5) { | ||
if(args.size() != 1) | ||
throw TerminativeThrowSignal( | ||
std::move(address), | ||
"Expecting 1 argument, got " + | ||
std::to_string(args.size()) | ||
); | ||
|
||
DynamicObject input = args.at(0); | ||
std::string md5 = input.toString(); | ||
return DynamicObject( | ||
std::regex_match( | ||
md5, | ||
std::regex("^[a-fA-F0-9]{32}$") | ||
) && md5.length() == 32 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2024 - Nathanne Isip | ||
* This file is part of N8. | ||
* | ||
* N8 is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, | ||
* or (at your option) any later version. | ||
* | ||
* N8 is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with N8. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef N8_STDLIB_CRYPT_CC | ||
#define N8_STDLIB_CRYPT_CC | ||
|
||
#ifdef __clang__ | ||
# pragma clang diagnostic push | ||
# pragma clang diagnostic ignored "-Wreturn-type-c-linkage" | ||
#endif | ||
|
||
#include "N8Library.hpp" | ||
|
||
N8_LIB_START | ||
|
||
N8_FUNC(crypt_md5); | ||
N8_FUNC(crypt_validateMd5); | ||
|
||
N8_LIB_END | ||
|
||
#ifdef __clang__ | ||
# pragma clang diagnostic pop | ||
#endif | ||
|
||
#endif |