1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/freebl/secmpi.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,32 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "mpi.h" 1.9 + 1.10 +#define CHECK_SEC_OK(func) if (SECSuccess != (rv = func)) goto cleanup 1.11 + 1.12 +#define CHECK_MPI_OK(func) if (MP_OKAY > (err = func)) goto cleanup 1.13 + 1.14 +#define OCTETS_TO_MPINT(oc, mp, len) \ 1.15 + CHECK_MPI_OK(mp_read_unsigned_octets((mp), oc, len)) 1.16 + 1.17 +#define SECITEM_TO_MPINT(it, mp) \ 1.18 + CHECK_MPI_OK(mp_read_unsigned_octets((mp), (it).data, (it).len)) 1.19 + 1.20 +#define MPINT_TO_SECITEM(mp, it, arena) \ 1.21 + do { int mpintLen = mp_unsigned_octet_size(mp); \ 1.22 + if (mpintLen <= 0) {err = MP_RANGE; goto cleanup;} \ 1.23 + SECITEM_AllocItem(arena, (it), mpintLen); \ 1.24 + if ((it)->data == NULL) {err = MP_MEM; goto cleanup;} \ 1.25 + err = mp_to_unsigned_octets(mp, (it)->data, (it)->len); \ 1.26 + if (err < 0) goto cleanup; else err = MP_OKAY; \ 1.27 + } while (0) 1.28 + 1.29 +#define MP_TO_SEC_ERROR(err) \ 1.30 + switch (err) { \ 1.31 + case MP_MEM: PORT_SetError(SEC_ERROR_NO_MEMORY); break; \ 1.32 + case MP_RANGE: PORT_SetError(SEC_ERROR_BAD_DATA); break; \ 1.33 + case MP_BADARG: PORT_SetError(SEC_ERROR_INVALID_ARGS); break; \ 1.34 + default: PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); break; \ 1.35 + }