-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from socketlabs/usr/mike.boshuyzen/Add-api-key…
…-parser Usr/mike.boshuyzen/add api key parser
- Loading branch information
Showing
17 changed files
with
1,157 additions
and
28 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,16 @@ | ||
{ | ||
"ExpandedNodes": [ | ||
"", | ||
"\\InjectionApi", | ||
"\\InjectionApi\\Examples", | ||
"\\InjectionApi\\Examples\\ExampleCode", | ||
"\\InjectionApi\\Examples\\ExampleCode\\Basic", | ||
"\\InjectionApi\\Examples\\Index", | ||
"\\InjectionApi\\Examples\\Index\\Js", | ||
"\\InjectionApi\\src", | ||
"\\InjectionApi\\src\\Core", | ||
"\\InjectionApi\\src\\Core\\Models" | ||
], | ||
"SelectedNode": "\\InjectionApi\\Examples\\Index\\Js\\Index.js", | ||
"PreviewInSolutionExplorer": false | ||
} |
Binary file not shown.
Binary file added
BIN
+3.28 KB
.vs/socketlabs-php/FileContentIndex/087772e8-1259-4e99-b075-58c404dda629.vsidx
Binary file not shown.
Binary file added
BIN
+6.08 KB
.vs/socketlabs-php/FileContentIndex/4efe6bc9-c0b5-431a-b76d-421956624cd4.vsidx
Binary file not shown.
Binary file added
BIN
+3.13 KB
.vs/socketlabs-php/FileContentIndex/ce21c6de-b9f7-48c3-9032-b53cea62b872.vsidx
Binary file not shown.
Binary file added
BIN
+171 KB
.vs/socketlabs-php/FileContentIndex/d38cfa93-a382-4660-bebd-474f9477f27f.vsidx
Binary file not shown.
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,46 @@ | ||
<?php | ||
|
||
namespace Socketlabs\Core; | ||
|
||
/** | ||
* A code describing the result of an attempt to parse an Api key. | ||
*/ | ||
abstract class ApiKeyParseResult | ||
{ | ||
/// <summary> | ||
/// No result could be produced. | ||
/// </summary> | ||
const None = "None"; | ||
/// <summary> | ||
/// The key was found to be the improper length. | ||
/// </summary> | ||
const InvalidKeyLength = "InvalidKeyLength"; | ||
/// <summary> | ||
/// The key was found to be blank or invalid. | ||
/// </summary> | ||
const InvalidEmptyOrWhitespace = "InvalidEmptyOrWhitespace"; | ||
/// <summary> | ||
/// The key was found to be blank or invalid. | ||
/// </summary> | ||
const Invalid = "Invalid"; | ||
/// <summary> | ||
/// The public portion of the key was unable to be parsed. | ||
/// </summary> | ||
const InvalidUnableToExtractPublicPart = "InvalidUnableToExtractPublicPart"; | ||
/// <summary> | ||
/// The secret portion of the key was unable to be parsed. | ||
/// </summary> | ||
const InvalidUnableToExtractSecretPart = "InvalidUnableToExtractSecretPart"; | ||
/// <summary> | ||
/// The public portion of the key has an invalid length. | ||
/// </summary> | ||
const InvalidPublicPartLength = "InvalidPublicPartLength"; | ||
/// <summary> | ||
/// The secret portion of the key has an invalid length. | ||
/// </summary> | ||
const InvalidSecretPartLength = "InvalidSecretPartLength"; | ||
/// <summary> | ||
/// Key was successfully parsed. | ||
/// </summary> | ||
const Success = "Success"; | ||
} |
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,61 @@ | ||
<?php | ||
namespace Socketlabs\Core; | ||
/** | ||
* Contains the method for parsing the Api Key. | ||
*/ | ||
class ApiKeyParser { | ||
|
||
/** Parse the API key to determine what kind of key was provided | ||
. */ | ||
public function parse($wholeApiKey) | ||
{ | ||
|
||
if ($wholeApiKey == null || trim($wholeApiKey) == '') | ||
{ | ||
$result = ApiKeyParseResult::InvalidEmptyOrWhitespace; | ||
return $result; | ||
} | ||
|
||
if (strlen($wholeApiKey) !== 61) | ||
{ | ||
$result = ApiKeyParseResult::InvalidKeyLength; | ||
return $result; | ||
} | ||
|
||
$splitPosition = strpos($wholeApiKey, '.'); | ||
|
||
if ($splitPosition === false) | ||
{ | ||
$result = ApiKeyParseResult::Invalid; | ||
return $result; | ||
} | ||
|
||
//extract the public part | ||
$maxCount = min(50, strlen($wholeApiKey)); | ||
|
||
if ($splitPosition === false) | ||
{ | ||
$result = ApiKeyParseResult::InvalidUnableToExtractPublicPart; | ||
return $result; | ||
} | ||
|
||
$publicPart = substr($wholeApiKey,0, $splitPosition); | ||
|
||
if (strlen($publicPart) !== 20) | ||
{ | ||
$result = ApiKeyParseResult::InvalidPublicPartLength; | ||
return $result; | ||
} | ||
|
||
$privatePart = substr($wholeApiKey, ($splitPosition + 1), strlen($wholeApiKey)); | ||
|
||
if (strlen($privatePart) !== 40) | ||
{ | ||
$result = ApiKeyParseResult::InvalidSecretPartLength; | ||
return $result; | ||
} | ||
|
||
$result = ApiKeyParseResult::Success; | ||
return $result; | ||
} | ||
} |
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
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