Skip to content
Snippets Groups Projects
provider.hh 1.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    #ifndef __VEREIGN_IDENTITY_PROVIDER_HH
    #define __VEREIGN_IDENTITY_PROVIDER_HH
    
    #include <vereign/kvstore/crypto_storage.hh>
    
    #include <mutex>
    
    namespace vereign::identity {
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    /**
     * Identity provider that manages the locally stored user identity.
     *
     * All public methods are thread safe.
     */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    class Provider {
    public:
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      /**
       * Creates Provider instance.
       *
       * @param storage The crypto storage used for read/write identity properties.
       */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      Provider(kvstore::CryptoStorage& storage);
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      /**
       * Default constructor.
       *
       * Does nothing.
       */
      ~Provider();
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      // disable copying
      Provider(const kvstore::Storage&) = delete;
      auto operator=(const kvstore::Storage&) -> Provider& = delete;
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      /**
       * Replaces the current identity.
       *
       * @param pin Required only under Linux. The pin code used for derivation of the crypto storage
       *    master key.
       *
       * @returns The base64 encoded PEM encoded identity public key.
       */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      auto ResetIdentity(const std::string& pin) -> std::string;
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    
      /**
       * Loads the local identity.
       *
       * @param pin Required only under Linux. The pin code used for derivation of the crypto storage
       *    master key.
       *
       * @returns The base64 encoded PEM encoded identity public key.
       */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      auto LoadIdentity(const std::string& pin) -> std::string;
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    
      /**
       * Retrieve identity public key.
       *
       * @returns The base64 encoded PEM encoded identity public key.
       */
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      auto GetIdentityPublicKeyBase64() -> std::string;
    
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
      /**
       * @returns base64 encoded SHA1 hash of the identity public key.
       */
      auto GetDeviceHash() -> std::string;
    
    Daniel Lyubomirov's avatar
    Daniel Lyubomirov committed
    
    private:
      std::mutex mu_;
    
      kvstore::CryptoStorage& storage_;
    };
    
    } // namespace vereign::identity
    
    #endif // __VEREIGN_IDENTITY_PROVIDER_HH