1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef dtls_identity_h__
7 #define dtls_identity_h__
11 #include "m_cpp_utils.h"
12 #include "mozilla/RefPtr.h"
13 #include "nsISupportsImpl.h"
14 #include "ScopedNSSTypes.h"
16 // All code in this module requires NSS to be live.
17 // Callers must initialize NSS and implement the nsNSSShutdownObject
26 // Generate an identity with a random name.
27 static TemporaryRef
<DtlsIdentity
> Generate();
29 // Note: the following two functions just provide access. They
30 // do not transfer ownership. If you want a pointer that lasts
31 // past the lifetime of the DtlsIdentity, you must make
33 CERTCertificate
*cert() { return cert_
; }
34 SECKEYPrivateKey
*privkey() { return privkey_
; }
36 nsresult
ComputeFingerprint(const std::string algorithm
,
37 unsigned char *digest
,
39 std::size_t *digest_length
);
41 static nsresult
ComputeFingerprint(const CERTCertificate
*cert
,
42 const std::string algorithm
,
43 unsigned char *digest
,
45 std::size_t *digest_length
);
46 static const std::string DEFAULT_HASH_ALGORITHM
;
48 HASH_ALGORITHM_MAX_LENGTH
= 64
51 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DtlsIdentity
)
54 DtlsIdentity(SECKEYPrivateKey
*privkey
, CERTCertificate
*cert
)
55 : privkey_(privkey
), cert_(cert
) {}
56 DISALLOW_COPY_ASSIGN(DtlsIdentity
);
58 ScopedSECKEYPrivateKey privkey_
;
59 CERTCertificate
*cert_
; // TODO: Using a smart pointer here causes link