Home | History | Annotate | Download | only in trunks
      1 //
      2 // Copyright (C) 2014 The Android Open Source Project
      3 //
      4 // Licensed under the Apache License, Version 2.0 (the "License");
      5 // you may not use this file except in compliance with the License.
      6 // You may obtain a copy of the License at
      7 //
      8 //      http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unless required by applicable law or agreed to in writing, software
     11 // distributed under the License is distributed on an "AS IS" BASIS,
     12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 // See the License for the specific language governing permissions and
     14 // limitations under the License.
     15 //
     16 
     17 #ifndef TRUNKS_TRUNKS_FACTORY_H_
     18 #define TRUNKS_TRUNKS_FACTORY_H_
     19 
     20 #include <memory>
     21 #include <string>
     22 
     23 #include <base/macros.h>
     24 
     25 #include "trunks/authorization_delegate.h"
     26 #include "trunks/blob_parser.h"
     27 #include "trunks/hmac_session.h"
     28 #include "trunks/policy_session.h"
     29 #include "trunks/session_manager.h"
     30 #include "trunks/tpm_state.h"
     31 #include "trunks/tpm_utility.h"
     32 #include "trunks/trunks_export.h"
     33 
     34 namespace trunks {
     35 
     36 class Tpm;
     37 
     38 // TrunksFactory is an interface to act as a factory for trunks objects. This
     39 // mechanism assists in injecting mocks for testing.
     40 class TRUNKS_EXPORT TrunksFactory {
     41  public:
     42   TrunksFactory() {}
     43   virtual ~TrunksFactory() {}
     44 
     45   // Returns a Tpm instance. The caller does not take ownership. All calls to
     46   // this method on a given TrunksFactory instance will return the same value.
     47   virtual Tpm* GetTpm() const = 0;
     48 
     49   // Returns an uninitialized TpmState instance. The caller takes ownership.
     50   virtual std::unique_ptr<TpmState> GetTpmState() const = 0;
     51 
     52   // Returns a TpmUtility instance. The caller takes ownership.
     53   virtual std::unique_ptr<TpmUtility> GetTpmUtility() const = 0;
     54 
     55   // Returns an AuthorizationDelegate instance for basic password authorization.
     56   // The caller takes ownership.
     57   virtual std::unique_ptr<AuthorizationDelegate> GetPasswordAuthorization(
     58       const std::string& password) const = 0;
     59 
     60   // Returns a SessionManager instance. The caller takes ownership.
     61   virtual std::unique_ptr<SessionManager> GetSessionManager() const = 0;
     62 
     63   // Returns a HmacSession instance. The caller takes ownership.
     64   virtual std::unique_ptr<HmacSession> GetHmacSession() const = 0;
     65 
     66   // Returns a PolicySession instance. The caller takes ownership.
     67   virtual std::unique_ptr<PolicySession> GetPolicySession() const = 0;
     68 
     69   // Returns a TrialSession instance. The caller takes ownership.
     70   virtual std::unique_ptr<PolicySession> GetTrialSession() const = 0;
     71 
     72   // Returns a BlobParser instance. The caller takes ownership.
     73   virtual std::unique_ptr<BlobParser> GetBlobParser() const = 0;
     74 
     75  private:
     76   DISALLOW_COPY_AND_ASSIGN(TrunksFactory);
     77 };
     78 
     79 }  // namespace trunks
     80 
     81 #endif  // TRUNKS_TRUNKS_FACTORY_H_
     82