You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

52 lines
1.4 KiB

  1. /* Copyright (c) 2016, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #include <openssl/bytestring.h>
  15. #include <assert.h>
  16. #include <limits.h>
  17. #include <string.h>
  18. #include <openssl/mem.h>
  19. #include "internal.h"
  20. int CBB_finish_i2d(CBB *cbb, uint8_t **outp) {
  21. assert(cbb->base->can_resize);
  22. uint8_t *der;
  23. size_t der_len;
  24. if (!CBB_finish(cbb, &der, &der_len)) {
  25. CBB_cleanup(cbb);
  26. return -1;
  27. }
  28. if (der_len > INT_MAX) {
  29. OPENSSL_free(der);
  30. return -1;
  31. }
  32. if (outp != NULL) {
  33. if (*outp == NULL) {
  34. *outp = der;
  35. der = NULL;
  36. } else {
  37. memcpy(*outp, der, der_len);
  38. *outp += der_len;
  39. }
  40. }
  41. OPENSSL_free(der);
  42. return (int)der_len;
  43. }