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 CLOUD_PRINT_GCP20_PROTOTYPE_X_PRIVET_TOKEN_H_ 6#define CLOUD_PRINT_GCP20_PROTOTYPE_X_PRIVET_TOKEN_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/gtest_prod_util.h" 12#include "base/time/time.h" 13 14// Class for generating and checking X-Privet-Token. 15class XPrivetToken { 16 public: 17 // Initializes the object. 18 XPrivetToken(); 19 20 // Destroys the object. 21 ~XPrivetToken() {} 22 23 // Generates X-Privet-Token for /privet/info request. Updates secret 24 // if expired. 25 std::string GenerateXToken(); 26 27 // Checks 28 bool CheckValidXToken(const std::string& token) const; 29 30 private: 31 FRIEND_TEST_ALL_PREFIXES(XPrivetTokenTest, Generation); 32 FRIEND_TEST_ALL_PREFIXES(XPrivetTokenTest, CheckingValid); 33 FRIEND_TEST_ALL_PREFIXES(XPrivetTokenTest, CheckingInvalid); 34 35 // For testing purposes. 36 XPrivetToken(const std::string& secret, const base::Time& gen_time); 37 38 // Generates X-Privet-Token for with certain time of issue. 39 std::string GenerateXTokenWithTime(uint64 issue_time) const; 40 41 // Creates new XPrivetToken secret. 42 void UpdateSecret(); 43 44 // X-Privet-Token secret. 45 std::string secret_; 46 47 // Time of last secret generation. 48 base::Time last_gen_time_; 49}; 50 51#endif // CLOUD_PRINT_GCP20_PROTOTYPE_X_PRIVET_TOKEN_H_ 52 53