OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef NET_CERT_INTERNAL_CERT_ISSUER_SOURCE_H_ | 5 #ifndef NET_CERT_INTERNAL_CERT_ISSUER_SOURCE_H_ |
6 #define NET_CERT_INTERNAL_CERT_ISSUER_SOURCE_H_ | 6 #define NET_CERT_INTERNAL_CERT_ISSUER_SOURCE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | |
12 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
13 #include "net/cert/internal/completion_status.h" | |
14 #include "net/cert/internal/parsed_certificate.h" | 12 #include "net/cert/internal/parsed_certificate.h" |
15 | 13 |
16 namespace net { | 14 namespace net { |
17 | 15 |
18 // Interface for looking up issuers of a certificate during path building. | 16 // Interface for looking up issuers of a certificate during path building. |
19 // Provides a synchronous and asynchronous method for retrieving issuers, so the | 17 // Provides a synchronous and asynchronous method for retrieving issuers, so the |
20 // path builder can try to complete synchronously first. The caller is expected | 18 // path builder can try to complete synchronously first. The caller is expected |
21 // to call SyncGetIssuersOf first, see if it can make progress with those | 19 // to call SyncGetIssuersOf first, see if it can make progress with those |
22 // results, and if not, then fall back to calling AsyncGetIssuersOf. | 20 // results, and if not, then fall back to calling AsyncGetIssuersOf. |
23 // An implementations may choose to return results from either one of the Get | 21 // An implementations may choose to return results from either one of the Get |
24 // methods, or from both. | 22 // methods, or from both. |
25 class NET_EXPORT CertIssuerSource { | 23 class NET_EXPORT CertIssuerSource { |
26 public: | 24 public: |
27 class NET_EXPORT Request { | 25 class NET_EXPORT Request { |
28 public: | 26 public: |
29 Request() = default; | 27 Request() = default; |
30 // Destruction of the Request cancels it. | 28 // Destruction of the Request cancels it. |
31 virtual ~Request() = default; | 29 virtual ~Request() = default; |
32 | 30 |
33 // Retrieves the next issuer. | 31 // Retrieves issuers and appends them to |issuers|. |
34 // | 32 // |
35 // If one is available it will be stored in |out_cert| and SYNC will be | 33 // GetNext should be called again to retrieve any remaining issuers. |
36 // returned. GetNext should be called again to retrieve any remaining | |
37 // issuers. | |
38 // | 34 // |
39 // If no issuers are currently available, |out_cert| will be cleared and the | 35 // If no issuers are left then |issuers| will not be modified. This |
40 // return value will indicate if the Request is exhausted. If the return | 36 // indicates that the issuers have been exhausted and GetNext() should |
41 // value is ASYNC, the |issuers_callback| that was passed to | 37 // not be called again. |
42 // AsyncGetIssuersOf will be called again (unless the Request is destroyed | 38 virtual void GetNext(ParsedCertificateList* issuers) = 0; |
43 // first). If the return value is SYNC, the Request is complete and the | |
44 // |issuers_callback| will not be called again. | |
45 virtual CompletionStatus GetNext( | |
46 scoped_refptr<ParsedCertificate>* out_cert) = 0; | |
47 | 39 |
48 private: | 40 private: |
49 DISALLOW_COPY_AND_ASSIGN(Request); | 41 DISALLOW_COPY_AND_ASSIGN(Request); |
50 }; | 42 }; |
51 | 43 |
52 using IssuerCallback = base::Callback<void(Request*)>; | |
53 | |
54 virtual ~CertIssuerSource() = default; | 44 virtual ~CertIssuerSource() = default; |
55 | 45 |
56 // Finds certificates whose Subject matches |cert|'s Issuer. | 46 // Finds certificates whose Subject matches |cert|'s Issuer. |
57 // Matches are appended to |issuers|. Any existing contents of |issuers| will | 47 // Matches are appended to |issuers|. Any existing contents of |issuers| will |
58 // not be modified. If the implementation does not support synchronous | 48 // not be modified. If the implementation does not support synchronous |
59 // lookups, or if there are no matches, |issuers| is not modified. | 49 // lookups, or if there are no matches, |issuers| is not modified. |
60 virtual void SyncGetIssuersOf(const ParsedCertificate* cert, | 50 virtual void SyncGetIssuersOf(const ParsedCertificate* cert, |
61 ParsedCertificateList* issuers) = 0; | 51 ParsedCertificateList* issuers) = 0; |
62 | 52 |
63 // Finds certificates whose Subject matches |cert|'s Issuer. | 53 // Finds certificates whose Subject matches |cert|'s Issuer. |
64 // If an async callback will be made |*out_req| is filled with a Request | 54 // If the implementation does not support asynchronous lookups or can |
65 // object which may be destroyed to cancel the callback. If the implementation | 55 // determine synchronously that it would return no results, |*out_req| |
66 // does not support asynchronous lookups or can determine synchronously that | 56 // will be set to nullptr. |
67 // it would return no results, |*out_req| will be set to nullptr. | |
68 // | 57 // |
69 // When matches are available or the request is complete, |issuers_callback| | 58 // Otherwise a request is started and saved to |out_req|. The results can be |
70 // will be called with a pointer to the same Request. The Request::GetNext | 59 // read through the Request interface. |
71 // method may then be used to iterate through the retrieved issuers. Note that | |
72 // |issuers_callback| may be called multiple times. See the documentation for | |
73 // Request::GetNext for more details. | |
74 virtual void AsyncGetIssuersOf(const ParsedCertificate* cert, | 60 virtual void AsyncGetIssuersOf(const ParsedCertificate* cert, |
75 const IssuerCallback& issuers_callback, | |
76 std::unique_ptr<Request>* out_req) = 0; | 61 std::unique_ptr<Request>* out_req) = 0; |
77 }; | 62 }; |
78 | 63 |
79 } // namespace net | 64 } // namespace net |
80 | 65 |
81 #endif // NET_CERT_INTERNAL_CERT_ISSUER_SOURCE_H_ | 66 #endif // NET_CERT_INTERNAL_CERT_ISSUER_SOURCE_H_ |
OLD | NEW |