2020-12-12 22:35:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-12-12 22:35:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
2022-01-20 17:01:39 +00:00
|
|
|
#include <AK/Error.h>
|
2020-12-12 22:35:14 +00:00
|
|
|
#include <AK/StringView.h>
|
|
|
|
|
2022-02-15 21:25:25 +00:00
|
|
|
#ifdef KERNEL
|
|
|
|
# include <Kernel/KString.h>
|
|
|
|
#else
|
|
|
|
# include <AK/String.h>
|
|
|
|
#endif
|
|
|
|
|
2020-12-12 22:35:14 +00:00
|
|
|
namespace AK {
|
|
|
|
|
2021-04-18 17:06:36 +00:00
|
|
|
constexpr u8 decode_hex_digit(char digit)
|
|
|
|
{
|
|
|
|
if (digit >= '0' && digit <= '9')
|
|
|
|
return digit - '0';
|
|
|
|
if (digit >= 'a' && digit <= 'f')
|
|
|
|
return 10 + (digit - 'a');
|
|
|
|
if (digit >= 'A' && digit <= 'F')
|
|
|
|
return 10 + (digit - 'A');
|
|
|
|
return 255;
|
|
|
|
}
|
2021-04-13 19:49:05 +00:00
|
|
|
|
2022-01-20 17:01:39 +00:00
|
|
|
ErrorOr<ByteBuffer> decode_hex(StringView);
|
2020-12-12 22:35:14 +00:00
|
|
|
|
2022-02-15 21:25:25 +00:00
|
|
|
#ifdef KERNEL
|
|
|
|
ErrorOr<NonnullOwnPtr<Kernel::KString>> encode_hex(ReadonlyBytes);
|
|
|
|
#else
|
2020-12-12 22:35:14 +00:00
|
|
|
String encode_hex(ReadonlyBytes);
|
2022-02-15 21:25:25 +00:00
|
|
|
#endif
|
2020-12-12 22:35:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::decode_hex;
|
2021-04-13 19:49:05 +00:00
|
|
|
using AK::decode_hex_digit;
|
2020-12-12 22:35:14 +00:00
|
|
|
using AK::encode_hex;
|