1
// Copyright 2013 Google Inc. All Rights Reserved.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
15
// Author: jmaessen@google.com (Jan-Willem Maessen)
17
#ifndef PAGESPEED_KERNEL_UTIL_NONCE_GENERATOR_H_
18
#define PAGESPEED_KERNEL_UTIL_NONCE_GENERATOR_H_
20
#include "pagespeed/kernel/base/abstract_mutex.h"
21
#include "pagespeed/kernel/base/basictypes.h"
22
#include "pagespeed/kernel/base/scoped_ptr.h"
24
namespace net_instaweb {
26
// Abstract base class for a generator of cryptographic nonce values (ie a
27
// cryptographic random number generator).
28
class NonceGenerator {
30
virtual ~NonceGenerator();
31
// Generate a fresh, ideally cryptographic, nonce. Thread-safe.
35
// Takes ownership of mutex.
36
explicit NonceGenerator(AbstractMutex* mutex) : mutex_(mutex) { }
38
// Subclasses must implement this method. Locking is already handled.
39
virtual uint64 NewNonceImpl() = 0;
42
scoped_ptr<AbstractMutex> mutex_;
44
DISALLOW_COPY_AND_ASSIGN(NonceGenerator);
47
} // namespace net_instaweb
49
#endif // PAGESPEED_KERNEL_UTIL_NONCE_GENERATOR_H_