misc.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
  2. /*
  3. * Copyright 2016 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 "misc.h"
  18. #include <jose/b64.h>
  19. #include <string.h>
  20. bool
  21. encode_protected(json_t *obj)
  22. {
  23. json_t *p = NULL;
  24. if (json_unpack(obj, "{s?o}", "protected", &p) == -1)
  25. return false;
  26. if (!p || json_is_string(p))
  27. return true;
  28. if (!json_is_object(p))
  29. return false;
  30. return json_object_set_new(obj, "protected", jose_b64_enc_dump(p)) == 0;
  31. }
  32. void
  33. zero(void *mem, size_t len)
  34. {
  35. memset(mem, 0, len);
  36. }
  37. static void __attribute__((constructor))
  38. constructor(void)
  39. {
  40. json_object_seed(0);
  41. }