1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
16 #include "mozpkix/Input.h"
17 #include "mozpkix/Result.h"
19 #define MOZILLA_CT_ARRAY_LENGTH(x) (sizeof(x) / sizeof((x)[0]))
22 void operator()(CERTSubjectPublicKeyInfo
* value
) {
23 SECKEY_DestroySubjectPublicKeyInfo(value
);
25 void operator()(PK11Context
* value
) { PK11_DestroyContext(value
, true); }
26 void operator()(PK11SlotInfo
* value
) { PK11_FreeSlot(value
); }
27 void operator()(SECKEYPublicKey
* value
) { SECKEY_DestroyPublicKey(value
); }
28 void operator()(SECItem
* value
) { SECITEM_FreeItem(value
, true); }
32 struct MaybeDeleteHelper
{
33 void operator()(T
* ptr
) {
41 typedef std::unique_ptr
<CERTSubjectPublicKeyInfo
,
42 MaybeDeleteHelper
<CERTSubjectPublicKeyInfo
>>
43 UniqueCERTSubjectPublicKeyInfo
;
44 typedef std::unique_ptr
<PK11Context
, MaybeDeleteHelper
<PK11Context
>>
46 typedef std::unique_ptr
<PK11SlotInfo
, MaybeDeleteHelper
<PK11SlotInfo
>>
48 typedef std::unique_ptr
<SECKEYPublicKey
, MaybeDeleteHelper
<SECKEYPublicKey
>>
49 UniqueSECKEYPublicKey
;
50 typedef std::unique_ptr
<SECItem
, MaybeDeleteHelper
<SECItem
>> UniqueSECItem
;
55 // Reads a TLS-encoded variable length unsigned integer from |in|.
56 // The integer is expected to be in big-endian order, which is used by TLS.
57 // Note: checks if the output parameter overflows while reading.
58 // |length| indicates the size (in bytes) of the serialized integer.
59 template <size_t length
, typename T
>
60 mozilla::pkix::Result
ReadUint(mozilla::pkix::Reader
& in
, T
& out
);
62 // Reads a length-prefixed variable amount of bytes from |in|, updating |out|
63 // on success. |prefixLength| indicates the number of bytes needed to represent
65 template <size_t prefixLength
>
66 mozilla::pkix::Result
ReadVariableBytes(mozilla::pkix::Reader
& in
,
67 mozilla::pkix::Input
& out
);
70 } // namespace mozilla