OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "crypto/nss_key_util.h" | 5 #include "crypto/nss_key_util.h" |
6 | 6 |
7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
8 #include <keyhi.h> | 8 #include <keyhi.h> |
9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
| 12 #include <memory> |
| 13 |
12 #include "base/logging.h" | 14 #include "base/logging.h" |
13 #include "crypto/nss_util.h" | 15 #include "crypto/nss_util.h" |
14 | 16 |
15 #if defined(USE_NSS_CERTS) | 17 #if defined(USE_NSS_CERTS) |
16 #include <secmod.h> | 18 #include <secmod.h> |
17 #include "crypto/nss_util_internal.h" | 19 #include "crypto/nss_util_internal.h" |
18 #endif | 20 #endif |
19 | 21 |
20 namespace crypto { | 22 namespace crypto { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 #if defined(USE_NSS_CERTS) | 26 #if defined(USE_NSS_CERTS) |
25 | 27 |
26 struct PublicKeyInfoDeleter { | 28 struct PublicKeyInfoDeleter { |
27 inline void operator()(CERTSubjectPublicKeyInfo* spki) { | 29 inline void operator()(CERTSubjectPublicKeyInfo* spki) { |
28 SECKEY_DestroySubjectPublicKeyInfo(spki); | 30 SECKEY_DestroySubjectPublicKeyInfo(spki); |
29 } | 31 } |
30 }; | 32 }; |
31 | 33 |
32 typedef scoped_ptr<CERTSubjectPublicKeyInfo, PublicKeyInfoDeleter> | 34 typedef std::unique_ptr<CERTSubjectPublicKeyInfo, PublicKeyInfoDeleter> |
33 ScopedPublicKeyInfo; | 35 ScopedPublicKeyInfo; |
34 | 36 |
35 // Decodes |input| as a SubjectPublicKeyInfo and returns a SECItem containing | 37 // Decodes |input| as a SubjectPublicKeyInfo and returns a SECItem containing |
36 // the CKA_ID of that public key or nullptr on error. | 38 // the CKA_ID of that public key or nullptr on error. |
37 ScopedSECItem MakeIDFromSPKI(const std::vector<uint8_t>& input) { | 39 ScopedSECItem MakeIDFromSPKI(const std::vector<uint8_t>& input) { |
38 // First, decode and save the public key. | 40 // First, decode and save the public key. |
39 SECItem key_der; | 41 SECItem key_der; |
40 key_der.type = siBuffer; | 42 key_der.type = siBuffer; |
41 key_der.data = const_cast<unsigned char*>(input.data()); | 43 key_der.data = const_cast<unsigned char*>(input.data()); |
42 key_der.len = input.size(); | 44 key_der.len = input.size(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (!cka_id) | 156 if (!cka_id) |
155 return nullptr; | 157 return nullptr; |
156 | 158 |
157 return ScopedSECKEYPrivateKey( | 159 return ScopedSECKEYPrivateKey( |
158 PK11_FindKeyByKeyID(slot, cka_id.get(), nullptr)); | 160 PK11_FindKeyByKeyID(slot, cka_id.get(), nullptr)); |
159 } | 161 } |
160 | 162 |
161 #endif // defined(USE_NSS_CERTS) | 163 #endif // defined(USE_NSS_CERTS) |
162 | 164 |
163 } // namespace crypto | 165 } // namespace crypto |
OLD | NEW |