2020-12-12 22:35:14 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
2020-12-12 22:35:14 +00:00
|
|
|
*
|
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>
|
2024-06-17 22:12:53 +00:00
|
|
|
#include <AK/ByteString.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>
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString encode_hex(ReadonlyBytes);
|
2020-12-12 22:35:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:18:30 +00:00
|
|
|
#if USING_AK_GLOBALLY
|
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;
|
2022-11-26 11:18:30 +00:00
|
|
|
#endif
|