Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sal/rtl/random.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <sal/config.h>
21
22
#include <cstdio>
23
#include <cstdlib>
24
25
#include <sal/types.h>
26
#include <rtl/alloc.h>
27
#include <rtl/random.h>
28
#include <oslrandom.h>
29
30
namespace {
31
32
struct RandomPool_Impl
33
{
34
};
35
36
}
37
38
rtlRandomPool SAL_CALL rtl_random_createPool() noexcept
39
0
{
40
0
    RandomPool_Impl *pImpl = static_cast< RandomPool_Impl* >(rtl_allocateZeroMemory(sizeof(RandomPool_Impl)));
41
0
    return static_cast< rtlRandomPool >(pImpl);
42
0
}
43
44
void SAL_CALL rtl_random_destroyPool(rtlRandomPool Pool) noexcept
45
0
{
46
0
    RandomPool_Impl *pImpl = static_cast< RandomPool_Impl* >(Pool);
47
0
    if (pImpl)
48
0
    {
49
0
        rtl_freeZeroMemory (pImpl, sizeof(RandomPool_Impl));
50
0
    }
51
0
}
52
53
rtlRandomError SAL_CALL rtl_random_addBytes(
54
    rtlRandomPool Pool, const void *Buffer, sal_Size /*Bytes*/) noexcept
55
0
{
56
0
    RandomPool_Impl *pImpl = static_cast< RandomPool_Impl* >(Pool);
57
0
    const sal_uInt8 *pBuffer = static_cast< const sal_uInt8* >(Buffer);
58
59
0
    if (!pImpl || !pBuffer)
60
0
        return rtl_Random_E_Argument;
61
62
0
    return rtl_Random_E_None;
63
0
}
64
65
rtlRandomError SAL_CALL rtl_random_getBytes (
66
    rtlRandomPool, void *Buffer, sal_Size Bytes) noexcept
67
173k
{
68
173k
    sal_uInt8 *pBuffer = static_cast< sal_uInt8* >(Buffer);
69
70
173k
    if (!pBuffer)
71
0
        return rtl_Random_E_Argument;
72
73
173k
    if (!osl_get_system_random_data(static_cast<char*>(Buffer), Bytes))
74
0
    {
75
0
        ::std::fprintf(stderr, "rtl_random_getBytes(): cannot read random device, aborting.\n");
76
0
        ::std::abort();
77
0
    }
78
173k
    return rtl_Random_E_None;
79
173k
}
80
81
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */