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