1
0

alg_wrap.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
  2. /*
  3. * Copyright 2017 Red Hat, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include "../lib/hooks.h"
  18. #include <jose/jose.h>
  19. #include <assert.h>
  20. #include <string.h>
  21. int
  22. main(int argc, char *argv[])
  23. {
  24. for (const jose_hook_alg_t *a = jose_hook_alg_list(); a; a = a->next) {
  25. json_auto_t *jwk = json_pack("{s:s}", "alg", a->name);
  26. if (a->kind != JOSE_HOOK_ALG_KIND_WRAP)
  27. continue;
  28. fprintf(stderr, "alg: %s\n", a->name);
  29. if (strcmp(a->name, "dir") != 0)
  30. assert(jose_jwk_gen(NULL, jwk));
  31. for (const jose_hook_alg_t *b = jose_hook_alg_list(); b; b = b->next) {
  32. json_auto_t *cek = json_pack("{s:s}", "alg", b->name);
  33. json_auto_t *tst = json_pack("{s:s}", "alg", b->name);
  34. json_auto_t *rcp = json_object();
  35. json_auto_t *jwe = json_object();
  36. if (b->kind != JOSE_HOOK_ALG_KIND_ENCR)
  37. continue;
  38. fprintf(stderr, "\tenc: %s\n", b->name);
  39. if (strcmp(a->name, "dir") == 0) {
  40. json_decref(jwk);
  41. assert((jwk = json_deep_copy(cek)));
  42. assert(jose_jwk_gen(NULL, jwk));
  43. }
  44. assert(jose_jwk_gen(NULL, tst));
  45. assert(json_object_del(tst, "k") == 0);
  46. assert(a->wrap.wrp(a, NULL, jwe, rcp, jwk, cek));
  47. assert(a->wrap.unw(a, NULL, jwe, rcp, jwk, tst));
  48. assert(json_equal(cek, tst));
  49. }
  50. }
  51. return EXIT_SUCCESS;
  52. }