Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/security/manager/ssl/nsRandomGenerator.cpp
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#include "nsRandomGenerator.h"
6
7
#include "ScopedNSSTypes.h"
8
#include "nsNSSComponent.h"
9
#include "pk11pub.h"
10
#include "prerror.h"
11
#include "secerr.h"
12
13
NS_IMPL_ISUPPORTS(nsRandomGenerator, nsIRandomGenerator)
14
15
NS_IMETHODIMP
16
nsRandomGenerator::GenerateRandomBytes(uint32_t aLength,
17
                                       uint8_t** aBuffer)
18
0
{
19
0
  NS_ENSURE_ARG_POINTER(aBuffer);
20
0
  *aBuffer = nullptr;
21
0
22
0
  mozilla::UniquePK11SlotInfo slot(PK11_GetInternalSlot());
23
0
  if (!slot) {
24
0
    return NS_ERROR_FAILURE;
25
0
  }
26
0
27
0
  auto buf = static_cast<uint8_t*>(moz_xmalloc(aLength));
28
0
29
0
  SECStatus srv = PK11_GenerateRandomOnSlot(slot.get(), buf, aLength);
30
0
  if (srv != SECSuccess) {
31
0
    free(buf);
32
0
    return NS_ERROR_FAILURE;
33
0
  }
34
0
35
0
  *aBuffer = buf;
36
0
37
0
  return NS_OK;
38
0
}