15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "crypto/ec_signature_creator.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "crypto/ec_signature_creator_impl.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace crypto {
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ECSignatureCreatorFactory* g_factory_ = NULL;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ECSignatureCreator* ECSignatureCreator::Create(ECPrivateKey* key) {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (g_factory_)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return g_factory_->Create(key);
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new ECSignatureCreatorImpl(key);
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ECSignatureCreator::SetFactoryForTesting(
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ECSignatureCreatorFactory* factory) {
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We should always clear the factory after each test to avoid
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // use-after-free problems.
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(!g_factory_ || !factory);
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  g_factory_ = factory;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace crypto
35