-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- After der_unpack() use der_put_default() to allow defaults to be set - Before der_pack() use der_unput_default() to remove values matching the default
- Loading branch information
Showing
6 changed files
with
142 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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
#include <arpa2/quick-der.h> | ||
|
||
/* When the optional is absent, set its value to the default. | ||
* Since Quick DER does not process default values, this must be | ||
* done manually. The work can help to simplify programs, by | ||
* reducing the number of code paths and improve coverage. | ||
* | ||
* This function is not directly usable for CHOICE, which is | ||
* unrolled into a sequence of dercursor values that may or may | ||
* not have a value, but the multiplicity of the values is not | ||
* taken care of below. | ||
*/ | ||
void der_put_default (dercursor *optional, dercursor default_value) { | ||
if (optional->derptr == NULL) { | ||
*optional = default_value; | ||
} | ||
} |
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,12 @@ | ||
|
||
#include <arpa2/quick-der.h> | ||
|
||
/* Test if the appointed optional equals the default. If so, set it | ||
* to the default/absent entry, .derptr==NULL and .derlen==0 | ||
* This is useful prior to sending. | ||
*/ | ||
void der_unput_default (dercursor *optional, dercursor default_value) { | ||
if (der_cmp (*optional, default_value) == 0) { | ||
memset (optional, 0, sizeof (dercursor)); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -55,3 +55,4 @@ c_test(der_data) | |
c_test(int_putget) | ||
c_test(bool_putget) | ||
c_test(data_putget) | ||
c_test(default_putunput) |
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,91 @@ | ||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
|
||
#include <arpa2/quick-der.h> | ||
|
||
|
||
dercursor abba = { | ||
.derptr = "ABBA", | ||
.derlen = 4 | ||
}; | ||
|
||
dercursor ledz = { | ||
.derptr = "LED Zeppelin", | ||
.derlen = 12 | ||
}; | ||
|
||
dercursor ledy = { | ||
.derptr = "LED Zeppelinny", | ||
.derlen = 12 | ||
}; | ||
|
||
dercursor null = { | ||
.derptr = NULL, | ||
.derlen = 0 | ||
}; | ||
|
||
dercursor band; | ||
|
||
|
||
int errors = 0; | ||
|
||
|
||
void maybe (dercursor dflt) { | ||
der_put_default (&band, dflt); | ||
} | ||
|
||
|
||
void notbe (dercursor dflt) { | ||
der_unput_default (&band, dflt); | ||
} | ||
|
||
|
||
void should (dercursor target) { | ||
static int testnr = 0; | ||
if (der_cmp (band, target) != 0) { | ||
errors++; | ||
fprintf (stderr, "Test #%d failed; found \"%.*s\", expected \"%.*s\"\n", | ||
testnr, band.derlen, band.derptr, target.derlen, target.derptr); | ||
} | ||
testnr++; | ||
} | ||
|
||
|
||
int main (int argc, char *argv []) { | ||
errors = 0; | ||
band = null; | ||
should (null); | ||
maybe (abba); | ||
should (abba); | ||
maybe (abba); | ||
should (abba); | ||
maybe (ledz); | ||
should (abba); | ||
notbe (ledz); | ||
should (abba); | ||
notbe (abba); | ||
should (null); | ||
maybe (ledz); | ||
should (ledz); | ||
should (ledy); | ||
notbe (ledy); | ||
should (null); | ||
maybe (ledy); | ||
should (ledy); | ||
should (ledz); | ||
maybe (abba); | ||
should (ledy); | ||
should (ledz); | ||
maybe (ledz); | ||
should (ledy); | ||
should (ledz); | ||
maybe (null); | ||
should (ledz); | ||
should (ledy); | ||
notbe (ledz); | ||
should (null); | ||
exit (errors); | ||
} |