xref: /aosp_15_r20/external/cronet/crypto/scoped_lacontext.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2024 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef CRYPTO_SCOPED_LACONTEXT_H_
6*6777b538SAndroid Build Coastguard Worker #define CRYPTO_SCOPED_LACONTEXT_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #if defined(__OBJC__)
9*6777b538SAndroid Build Coastguard Worker #import <LocalAuthentication/LocalAuthentication.h>
10*6777b538SAndroid Build Coastguard Worker #endif  // defined(__OBJC__)
11*6777b538SAndroid Build Coastguard Worker 
12*6777b538SAndroid Build Coastguard Worker #include <memory>
13*6777b538SAndroid Build Coastguard Worker 
14*6777b538SAndroid Build Coastguard Worker #include "crypto/crypto_export.h"
15*6777b538SAndroid Build Coastguard Worker 
16*6777b538SAndroid Build Coastguard Worker namespace crypto {
17*6777b538SAndroid Build Coastguard Worker 
18*6777b538SAndroid Build Coastguard Worker // ScopedLAContext can hold an `LAContext` and is safe to pass around from C++.
19*6777b538SAndroid Build Coastguard Worker // ScopedLAContext functions as a unique pointer. The UI can create one with an
20*6777b538SAndroid Build Coastguard Worker // authenticated LAContext, then pass it down to the platform.
21*6777b538SAndroid Build Coastguard Worker class CRYPTO_EXPORT ScopedLAContext {
22*6777b538SAndroid Build Coastguard Worker  public:
23*6777b538SAndroid Build Coastguard Worker #if defined(__OBJC__)
24*6777b538SAndroid Build Coastguard Worker   // Takes ownership of |lacontext|.
25*6777b538SAndroid Build Coastguard Worker   explicit ScopedLAContext(LAContext* lacontext);
26*6777b538SAndroid Build Coastguard Worker #endif  // defined(__OBJC__)
27*6777b538SAndroid Build Coastguard Worker   ~ScopedLAContext();
28*6777b538SAndroid Build Coastguard Worker   ScopedLAContext(ScopedLAContext&) = delete;
29*6777b538SAndroid Build Coastguard Worker   ScopedLAContext(ScopedLAContext&&);
30*6777b538SAndroid Build Coastguard Worker   ScopedLAContext& operator=(const ScopedLAContext&) = delete;
31*6777b538SAndroid Build Coastguard Worker   ScopedLAContext& operator=(ScopedLAContext&&);
32*6777b538SAndroid Build Coastguard Worker 
33*6777b538SAndroid Build Coastguard Worker #if defined(__OBJC__)
34*6777b538SAndroid Build Coastguard Worker   // release returns the last `LAContext` passed on construction and drops its
35*6777b538SAndroid Build Coastguard Worker   // reference to it. It is invalid to to call release more than once.
36*6777b538SAndroid Build Coastguard Worker   LAContext* release();
37*6777b538SAndroid Build Coastguard Worker #endif  // defined(__OBJC__)
38*6777b538SAndroid Build Coastguard Worker 
39*6777b538SAndroid Build Coastguard Worker  private:
40*6777b538SAndroid Build Coastguard Worker   struct ObjCStorage;
41*6777b538SAndroid Build Coastguard Worker   std::unique_ptr<ObjCStorage> storage_;
42*6777b538SAndroid Build Coastguard Worker };
43*6777b538SAndroid Build Coastguard Worker 
44*6777b538SAndroid Build Coastguard Worker }  // namespace crypto
45*6777b538SAndroid Build Coastguard Worker 
46*6777b538SAndroid Build Coastguard Worker #endif  // CRYPTO_SCOPED_LACONTEXT_H_
47