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