Home | History | Annotate | Download | only in common
      1 //
      2 // Copyright (C) 2015 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 #include "attestation/common/mock_crypto_utility.h"
     18 
     19 using ::testing::_;
     20 using ::testing::Invoke;
     21 using ::testing::Return;
     22 using ::testing::WithArgs;
     23 
     24 namespace {
     25 
     26 bool FakeRandom(size_t num_bytes, std::string* output) {
     27   *output = std::string(num_bytes, 'A');
     28   return true;
     29 }
     30 
     31 bool CopyString(const std::string& s1, std::string* s2) {
     32   *s2 = s1;
     33   return true;
     34 }
     35 
     36 }  // namespace
     37 
     38 namespace attestation {
     39 
     40 MockCryptoUtility::MockCryptoUtility() {
     41   ON_CALL(*this, GetRandom(_, _)).WillByDefault(Invoke(FakeRandom));
     42   ON_CALL(*this, CreateSealedKey(_, _)).WillByDefault(Return(true));
     43   ON_CALL(*this, UnsealKey(_, _, _)).WillByDefault(Return(true));
     44   ON_CALL(*this, EncryptData(_, _, _, _))
     45       .WillByDefault(WithArgs<0, 3>(Invoke(CopyString)));
     46   ON_CALL(*this, DecryptData(_, _, _))
     47       .WillByDefault(WithArgs<0, 2>(Invoke(CopyString)));
     48   ON_CALL(*this, GetRSASubjectPublicKeyInfo(_, _))
     49       .WillByDefault(Invoke(CopyString));
     50 }
     51 
     52 MockCryptoUtility::~MockCryptoUtility() {}
     53 
     54 }  // namespace attestation
     55