Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "mpi.h" |
michael@0 | 6 | |
michael@0 | 7 | #define CHECK_SEC_OK(func) if (SECSuccess != (rv = func)) goto cleanup |
michael@0 | 8 | |
michael@0 | 9 | #define CHECK_MPI_OK(func) if (MP_OKAY > (err = func)) goto cleanup |
michael@0 | 10 | |
michael@0 | 11 | #define OCTETS_TO_MPINT(oc, mp, len) \ |
michael@0 | 12 | CHECK_MPI_OK(mp_read_unsigned_octets((mp), oc, len)) |
michael@0 | 13 | |
michael@0 | 14 | #define SECITEM_TO_MPINT(it, mp) \ |
michael@0 | 15 | CHECK_MPI_OK(mp_read_unsigned_octets((mp), (it).data, (it).len)) |
michael@0 | 16 | |
michael@0 | 17 | #define MPINT_TO_SECITEM(mp, it, arena) \ |
michael@0 | 18 | do { int mpintLen = mp_unsigned_octet_size(mp); \ |
michael@0 | 19 | if (mpintLen <= 0) {err = MP_RANGE; goto cleanup;} \ |
michael@0 | 20 | SECITEM_AllocItem(arena, (it), mpintLen); \ |
michael@0 | 21 | if ((it)->data == NULL) {err = MP_MEM; goto cleanup;} \ |
michael@0 | 22 | err = mp_to_unsigned_octets(mp, (it)->data, (it)->len); \ |
michael@0 | 23 | if (err < 0) goto cleanup; else err = MP_OKAY; \ |
michael@0 | 24 | } while (0) |
michael@0 | 25 | |
michael@0 | 26 | #define MP_TO_SEC_ERROR(err) \ |
michael@0 | 27 | switch (err) { \ |
michael@0 | 28 | case MP_MEM: PORT_SetError(SEC_ERROR_NO_MEMORY); break; \ |
michael@0 | 29 | case MP_RANGE: PORT_SetError(SEC_ERROR_BAD_DATA); break; \ |
michael@0 | 30 | case MP_BADARG: PORT_SetError(SEC_ERROR_INVALID_ARGS); break; \ |
michael@0 | 31 | default: PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); break; \ |
michael@0 | 32 | } |