OpenVPN 3 Core Library
Loading...
Searching...
No Matches
tmpfilename.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#pragma once
13
17
18namespace openvpn {
19
20// Generate a temporary filename that is a variant
21// of an existing filename.
22inline std::string tmp_filename(const std::string &fn,
23 const std::string &tmpdir,
24 StrongRandomAPI &rng)
25{
26 unsigned char data[16];
27 rng.rand_fill(data);
28 return path::join(tmpdir, '.' + path::basename(fn).substr(0, 64) + '.' + render_hex(data, sizeof(data)));
29}
30
31} // namespace openvpn
void rand_fill(T &obj)
Fill a data object with random bytes.
Definition randapi.hpp:75
Abstract base class for cryptographically strong random number generators.
Definition randapi.hpp:228
std::string basename(const std::string &path)
Definition path.hpp:76
std::string join(const std::string &p1, const std::string &p2)
Definition path.hpp:180
Support deferred server-side state creation when client connects.
Definition ovpncli.cpp:95
std::string tmp_filename(const std::string &fn, const std::string &tmpdir, StrongRandomAPI &rng)
std::string render_hex(const unsigned char *data, size_t size, const bool caps=false)
Definition hexstr.hpp:135
Implementation of the base classes for random number generators.