-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.c
More file actions
112 lines (100 loc) · 4.41 KB
/
Copy pathtests.c
File metadata and controls
112 lines (100 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* The MIT License (MIT)
*
* Copyright (c) 2016 Smartex.io Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "smartex.h"
static void runPublicKeyTest();
static void runSinTest();
static void runSignatureTest();
int main() {
runPublicKeyTest();
runSinTest();
runSignatureTest();
return 0;
}
static void runSignatureTest() {
int signa;
char *message = "https://smartex.io/invoices{\"currency\":\"USD\",\"price\":10,\"token\":\"3yHuXP7GVbqEh1rsDaodCzbMR5TZsxbMHEPnigsKyY86\"}";
char *pem = malloc(240);
char *signature = calloc(145, sizeof(char));
char *actual_start = calloc(4, sizeof(char));
char *expected_start = calloc(5, sizeof(char));
pem[239]='\0';
generatePem(&pem);
signa = signMessageWithPem(message, pem, &signature);
if (signa == ERROR) {
printf("Signature Error.\n");
};
actual_start[3] = '\0';
memcpy(actual_start, signature, 4);
if (strlen(signature) == 138) {
memcpy(expected_start, "3043", 4);
expected_start[4] = '\0';
} else if (strlen(signature) == 140) {
memcpy(expected_start, "3044", 4);
expected_start[4] = '\0';
} else if (strlen(signature) == 142) {
memcpy(expected_start, "3045", 4);
expected_start[4] = '\0';
} else if (strlen(signature) == 144) {
memcpy(expected_start, "3046", 4);
expected_start[4] = '\0';
} else {
printf("%lu is not a valid signature length\n", (unsigned long)strlen(signature));
}
if (strcmp(actual_start, expected_start) == 0)
printf("[PASSED] Signature Test - Expected: %s - Actual: %s for %s\n", expected_start, actual_start, signature);
else
printf("[FAILED] Signature Test - Expected: %s - Actual: %s for %s\n", expected_start, actual_start, signature);
printf("\n");
free(expected_start);
free(pem);
free(signature);
free(actual_start);
}
static void runSinTest() {
char *fixed_pem = "-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEILrVeiUtzVEodjMvTsMwKYDMn+0UN5fzCRY3vozAsRZnoAcGBSuBBAAK\noUQDQgAE8Db3K3DhLumyt3haSuAlu74pXf7nd2nhVKdlbrp/cwe7AhU2Dj5aCbPX\n2aZXU/fGVlg8kwSt9fjlSFipl1wVvw==\n-----END EC PRIVATE KEY-----\n";
int singood;
char *expected_sin = "Tf5tYNrKfAdiSjuzsZwRbne6QyWpgKtH6DZ";
char *sin = calloc(35, sizeof(char));
singood = generateSinFromPem(fixed_pem, &sin);
if (singood == ERROR)
printf("Sin Error\n");
if (strcmp(expected_sin, sin) == 0)
printf("[PASSED] Sin Test - Expected: %s - Actual: %s\n", expected_sin, sin);
else
printf("[FAILED] Sin Test - Expected: %s - Actual: %s\n", expected_sin, sin);
free(sin);
}
static void runPublicKeyTest(){
char *pub = malloc(67);
char *fixed_pem = "-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEILrVeiUtzVEodjMvTsMwKYDMn+0UN5fzCRY3vozAsRZnoAcGBSuBBAAK\noUQDQgAE8Db3K3DhLumyt3haSuAlu74pXf7nd2nhVKdlbrp/cwe7AhU2Dj5aCbPX\n2aZXU/fGVlg8kwSt9fjlSFipl1wVvw==\n-----END EC PRIVATE KEY-----\n";
char *expected_pub = "03F036F72B70E12EE9B2B7785A4AE025BBBE295DFEE77769E154A7656EBA7F7307";
int pubgood = getPublicKeyFromPem(fixed_pem, &pub);
if (pubgood == ERROR)
printf("Error retrieving public key\n");
if (strcmp(expected_pub, pub) == 0)
printf("[PASSED] Public Key Test - Expected: %s - Actual: %s\n", expected_pub, pub);
else
printf("[FAILED] Public Key Test - Expected: %s - Actual: %s\n", expected_pub, pub);
free(pub);
}