-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df99404
commit 033c331
Showing
23 changed files
with
996 additions
and
841 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,88 @@ | ||
--- | ||
BasedOnStyle: Microsoft | ||
AccessModifierOffset: -4 | ||
AlignAfterOpenBracket: DontAlign | ||
AlignConsecutiveAssignments: false | ||
AlignConsecutiveDeclarations: false | ||
AlignEscapedNewlines: Right | ||
AlignOperands: true | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: None | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
AlwaysBreakTemplateDeclarations: Yes | ||
BinPackArguments: true | ||
BinPackParameters: true | ||
BraceWrapping: | ||
AfterClass: true | ||
AfterControlStatement: true | ||
AfterEnum: true | ||
AfterFunction: true | ||
AfterNamespace: true | ||
AfterObjCDeclaration: false | ||
AfterStruct: true | ||
AfterUnion: true | ||
BeforeCatch: true | ||
BeforeElse: true | ||
IndentBraces: false | ||
SplitEmptyFunction: true | ||
SplitEmptyRecord: true | ||
SplitEmptyNamespace: true | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeBraces: Custom | ||
BreakBeforeTernaryOperators: false | ||
BreakConstructorInitializers: BeforeColon | ||
PackConstructorInitializers: Never | ||
ColumnLimit: 152 | ||
CommentPragmas: '^ IWYU pragma:' | ||
CompactNamespaces: false | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
ConstructorInitializerIndentWidth: 4 | ||
ContinuationIndentWidth: 4 | ||
Cpp11BracedListStyle: true | ||
DerivePointerAlignment: false | ||
DisableFormat: false | ||
ExperimentalAutoDetectBinPacking: false | ||
FixNamespaceComments: true | ||
IndentCaseLabels: true | ||
IndentExternBlock: NoIndent | ||
IndentWidth: 4 | ||
IndentPPDirectives: AfterHash | ||
IndentWrappedFunctionNames: true | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
MacroBlockBegin: '' | ||
MacroBlockEnd: '' | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: None | ||
PenaltyBreakComment: 300 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakOpenParenthesis: 100 | ||
PenaltyBreakString: 1000 | ||
PenaltyExcessCharacter: 1 | ||
PenaltyReturnTypeOnItsOwnLine: 60 | ||
PointerAlignment: Left | ||
ReflowComments: true | ||
SortIncludes: CaseSensitive | ||
SpaceAfterCStyleCast: false | ||
SpaceAfterLogicalNot: false | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: ControlStatementsExceptControlMacros | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInContainerLiterals: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
Standard: Cpp11 | ||
TabWidth: 4 | ||
UseCRLF: false | ||
UseTab: Never | ||
IndentAccessModifiers: false | ||
AccessModifierOffset: -4 | ||
EmptyLineBeforeAccessModifier: Always | ||
IncludeBlocks: Regroup |
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
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 |
---|---|---|
@@ -1,96 +1,98 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#include <string> | ||
#include "Result.h" | ||
#include "Base64.h" | ||
|
||
#include "Result.h" | ||
|
||
#include <string> | ||
|
||
namespace compliance | ||
{ | ||
static inline char Base64Char(const unsigned char c) | ||
static inline char Base64Char(const unsigned char c) | ||
{ | ||
if (c >= 'A' && c <= 'Z') | ||
{ | ||
if (c >= 'A' && c <= 'Z') | ||
{ | ||
return c - 'A'; | ||
} | ||
else if (c >= 'a' && c <= 'z') | ||
{ | ||
return c - 'a' + 26; | ||
} | ||
else if (c >= '0' && c <= '9') | ||
{ | ||
return c - '0' + 52; | ||
} | ||
else if (c == '+') | ||
{ | ||
return 62; | ||
} | ||
else if (c == '/') | ||
{ | ||
return 63; | ||
} | ||
else | ||
{ | ||
return 0; | ||
} | ||
return c - 'A'; | ||
} | ||
|
||
static inline bool IsBase64(const unsigned char c) | ||
else if (c >= 'a' && c <= 'z') | ||
{ | ||
return c - 'a' + 26; | ||
} | ||
else if (c >= '0' && c <= '9') | ||
{ | ||
return (isalnum(c) || (c == '+') || (c == '/') || (c == '=')); | ||
return c - '0' + 52; | ||
} | ||
else if (c == '+') | ||
{ | ||
return 62; | ||
} | ||
else if (c == '/') | ||
{ | ||
return 63; | ||
} | ||
else | ||
{ | ||
return 0; | ||
} | ||
} | ||
|
||
Result<std::string> Base64Decode(const std::string &input) | ||
static inline bool IsBase64(const unsigned char c) | ||
{ | ||
return (isalnum(c) || (c == '+') || (c == '/') || (c == '=')); | ||
} | ||
|
||
Result<std::string> Base64Decode(const std::string& input) | ||
{ | ||
if (input.size() % 4 != 0) | ||
{ | ||
return Error("Invalid base64 length", EINVAL); | ||
} | ||
for (const char c : input) | ||
{ | ||
if (input.size() % 4 != 0) | ||
if (!IsBase64(c)) | ||
{ | ||
return Error("Invalid base64 length", EINVAL); | ||
} | ||
for (const char c : input) | ||
{ | ||
if (!IsBase64(c)) | ||
{ | ||
return Error("Invalid base64 character", EINVAL); | ||
} | ||
return Error("Invalid base64 character", EINVAL); | ||
} | ||
} | ||
|
||
std::string ret; | ||
ret.reserve((input.size() * 3) / 4); | ||
std::string ret; | ||
ret.reserve((input.size() * 3) / 4); | ||
|
||
for (size_t i = 0; i < input.size(); i += 4) | ||
{ | ||
unsigned char enc[4]; | ||
for (size_t i = 0; i < input.size(); i += 4) | ||
{ | ||
unsigned char enc[4]; | ||
|
||
int j = 0; | ||
for (j = 0; j < 4; j++) | ||
int j = 0; | ||
for (j = 0; j < 4; j++) | ||
{ | ||
if (input[i + j] == '=') | ||
{ | ||
if (input[i+j] == '=') | ||
{ | ||
break; | ||
} | ||
enc[j] = Base64Char(input[i + j]); | ||
break; | ||
} | ||
enc[j] = Base64Char(input[i + j]); | ||
} | ||
|
||
if (j == 4) | ||
{ | ||
ret += (enc[0] << 2) | (enc[1] >> 4); | ||
ret += ((enc[1] & 0x0f) << 4) | (enc[2] >> 2); | ||
ret += ((enc[2] & 0x03) << 6) | enc[3]; | ||
} | ||
else if (j == 3) | ||
{ | ||
ret += (enc[0] << 2) | (enc[1] >> 4); | ||
ret += ((enc[1] & 0x0f) << 4) | (enc[2] >> 2); | ||
} | ||
else if (j == 2) | ||
{ | ||
ret += (enc[0] << 2) | (enc[1] >> 4); | ||
} | ||
else | ||
{ | ||
return Error("Invalid base64", EINVAL); | ||
} | ||
if (j == 4) | ||
{ | ||
ret += (enc[0] << 2) | (enc[1] >> 4); | ||
ret += ((enc[1] & 0x0f) << 4) | (enc[2] >> 2); | ||
ret += ((enc[2] & 0x03) << 6) | enc[3]; | ||
} | ||
else if (j == 3) | ||
{ | ||
ret += (enc[0] << 2) | (enc[1] >> 4); | ||
ret += ((enc[1] & 0x0f) << 4) | (enc[2] >> 2); | ||
} | ||
else if (j == 2) | ||
{ | ||
ret += (enc[0] << 2) | (enc[1] >> 4); | ||
} | ||
else | ||
{ | ||
return Error("Invalid base64", EINVAL); | ||
} | ||
return ret; | ||
} | ||
return ret; | ||
} | ||
} // namespace compliance |
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
#ifndef BASE64_H | ||
#define BASE64_H | ||
|
||
#include <string> | ||
#include "Result.h" | ||
|
||
#include <string> | ||
|
||
namespace compliance | ||
{ | ||
Result<std::string> Base64Decode(const std::string &input); | ||
Result<std::string> Base64Decode(const std::string& input); | ||
} | ||
|
||
#endif // BASE64_H |
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
Oops, something went wrong.