nacl_validation_cache.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef COMPONENTS_NACL_BROWSER_NACL_VALIDATION_CACHE_H_
  5. #define COMPONENTS_NACL_BROWSER_NACL_VALIDATION_CACHE_H_
  6. #include <stddef.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/containers/lru_cache.h"
  10. namespace base {
  11. class Pickle;
  12. }
  13. namespace nacl {
  14. class NaClValidationCache {
  15. public:
  16. NaClValidationCache();
  17. NaClValidationCache(const NaClValidationCache&) = delete;
  18. NaClValidationCache& operator=(const NaClValidationCache&) = delete;
  19. ~NaClValidationCache();
  20. // Get the key used for HMACing validation signatures. This should be a
  21. // string of cryptographically secure random bytes.
  22. const std::string& GetValidationCacheKey() const {
  23. return validation_cache_key_;
  24. }
  25. // Is the validation signature in the database?
  26. bool QueryKnownToValidate(const std::string& signature, bool reorder);
  27. // Put the validation signature in the database.
  28. void SetKnownToValidate(const std::string& signature);
  29. void Reset();
  30. void Serialize(base::Pickle* pickle) const;
  31. bool Deserialize(const base::Pickle* pickle);
  32. // Testing functions
  33. size_t size() const {
  34. return validation_cache_.size();
  35. }
  36. void SetValidationCacheKey(std::string& key) {
  37. validation_cache_key_ = key;
  38. }
  39. std::vector<std::string> GetContents() const {
  40. std::vector<std::string> contents;
  41. ValidationCacheType::const_iterator iter = validation_cache_.begin();
  42. for (iter = validation_cache_.begin();
  43. iter != validation_cache_.end();
  44. iter++) {
  45. contents.push_back(iter->first);
  46. }
  47. return contents;
  48. }
  49. private:
  50. bool DeserializeImpl(const base::Pickle* pickle);
  51. typedef base::HashingLRUCache<std::string, bool> ValidationCacheType;
  52. ValidationCacheType validation_cache_;
  53. std::string validation_cache_key_;
  54. };
  55. } // namespace nacl
  56. #endif // COMPONENTS_NACL_BROWSER_NACL_VALIDATION_CACHE_H_