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
|
/* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
/*
* Copyright 2017 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "../lib/hooks.h"
#include <jose/jose.h>
#include <assert.h>
#include <string.h>
int
main(int argc, char *argv[])
{
for (const jose_hook_alg_t *a = jose_hook_alg_list(); a; a = a->next) {
json_auto_t *jwk = json_pack("{s:s}", "alg", a->name);
if (a->kind != JOSE_HOOK_ALG_KIND_WRAP)
continue;
fprintf(stderr, "alg: %s\n", a->name);
if (strcmp(a->name, "dir") != 0)
assert(jose_jwk_gen(NULL, jwk));
for (const jose_hook_alg_t *b = jose_hook_alg_list(); b; b = b->next) {
json_auto_t *cek = json_pack("{s:s}", "alg", b->name);
json_auto_t *tst = json_pack("{s:s}", "alg", b->name);
json_auto_t *rcp = json_object();
json_auto_t *jwe = json_object();
if (b->kind != JOSE_HOOK_ALG_KIND_ENCR)
continue;
fprintf(stderr, "\tenc: %s\n", b->name);
if (strcmp(a->name, "dir") == 0) {
json_decref(jwk);
assert((jwk = json_deep_copy(cek)));
assert(jose_jwk_gen(NULL, jwk));
}
assert(jose_jwk_gen(NULL, tst));
assert(json_object_del(tst, "k") == 0);
assert(a->wrap.wrp(a, NULL, jwe, rcp, jwk, cek));
assert(a->wrap.unw(a, NULL, jwe, rcp, jwk, tst));
assert(json_equal(cek, tst));
}
}
return EXIT_SUCCESS;
}
|