1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_NACL_BROWSER_NACL_VALIDATION_CACHE_H_ 6 #define COMPONENTS_NACL_BROWSER_NACL_VALIDATION_CACHE_H_ 7 8 #include <vector> 9 10 #include "base/containers/mru_cache.h" 11 12 class Pickle; 13 14 namespace nacl { 15 16 class NaClValidationCache { 17 public: 18 NaClValidationCache(); 19 ~NaClValidationCache(); 20 21 // Get the key used for HMACing validation signatures. This should be a 22 // string of cryptographically secure random bytes. 23 const std::string& GetValidationCacheKey() const { 24 return validation_cache_key_; 25 } 26 27 // Is the validation signature in the database? 28 bool QueryKnownToValidate(const std::string& signature, bool reorder); 29 30 // Put the validation signature in the database. 31 void SetKnownToValidate(const std::string& signature); 32 33 void Reset(); 34 void Serialize(Pickle* pickle) const; 35 bool Deserialize(const Pickle* pickle); 36 37 // Testing functions 38 size_t size() const { 39 return validation_cache_.size(); 40 } 41 void SetValidationCacheKey(std::string& key) { 42 validation_cache_key_ = key; 43 } 44 std::vector<std::string> GetContents() const { 45 std::vector<std::string> contents; 46 ValidationCacheType::const_iterator iter = validation_cache_.begin(); 47 for (iter = validation_cache_.begin(); 48 iter != validation_cache_.end(); 49 iter++) { 50 contents.push_back(iter->first); 51 } 52 return contents; 53 } 54 55 private: 56 bool DeserializeImpl(const Pickle* pickle); 57 58 typedef base::HashingMRUCache<std::string, bool> ValidationCacheType; 59 ValidationCacheType validation_cache_; 60 61 std::string validation_cache_key_; 62 63 DISALLOW_COPY_AND_ASSIGN(NaClValidationCache); 64 }; 65 66 } // namespace nacl 67 68 #endif // COMPONENTS_NACL_BROWSER_NACL_VALIDATION_CACHE_H_ 69