tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

KeychainSecret.h (1271B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 *
      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/. */
      6 
      7 #ifndef KeychainSecret_h
      8 #define KeychainSecret_h
      9 
     10 #include "CoreFoundation/CFBase.h"
     11 
     12 #include "OSKeyStore.h"
     13 #include "nsString.h"
     14 
     15 template <typename T>
     16 class ScopedCFType {
     17 public:
     18  explicit ScopedCFType(T value) : mValue(value) {}
     19 
     20  MOZ_IMPLICIT ScopedCFType(decltype(nullptr)) : mValue(nullptr) {}
     21 
     22  ~ScopedCFType() {
     23    if (mValue) {
     24      CFRelease((CFTypeRef)mValue);
     25    }
     26  }
     27 
     28  T get() { return mValue; }
     29 
     30  explicit operator bool() const { return mValue != nullptr; }
     31 
     32 private:
     33  T mValue;
     34 };
     35 
     36 class KeychainSecret final : public AbstractOSKeyStore {
     37 public:
     38  KeychainSecret();
     39 
     40  virtual nsresult RetrieveSecret(const nsACString& label,
     41                                  /* out */ nsACString& secret) override;
     42  virtual nsresult StoreSecret(const nsACString& secret,
     43                               const nsACString& label) override;
     44  virtual nsresult DeleteSecret(const nsACString& label) override;
     45 
     46  virtual ~KeychainSecret();
     47 };
     48 
     49 #endif  // KeychainSecret_h