2020-12-12 17:35:14 -05:00
|
|
|
/*
|
2024-10-04 07:19:50 -04:00
|
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
2020-12-12 17:35:14 -05:00
|
|
|
*
|
2021-04-22 04:24:48 -04:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-12-12 17:35:14 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
2024-06-17 18:12:53 -04:00
|
|
|
#include <AK/ByteString.h>
|
2022-01-20 12:01:39 -05:00
|
|
|
#include <AK/Error.h>
|
2020-12-12 17:35:14 -05:00
|
|
|
#include <AK/StringView.h>
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
2021-04-18 13:06:36 -04: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 15:49:05 -04:00
|
|
|
|
2022-01-20 12:01:39 -05:00
|
|
|
ErrorOr<ByteBuffer> decode_hex(StringView);
|
2020-12-12 17:35:14 -05:00
|
|
|
|
2023-12-16 09:19:34 -05:00
|
|
|
ByteString encode_hex(ReadonlyBytes);
|
2020-12-12 17:35:14 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-26 06:18:30 -05:00
|
|
|
#if USING_AK_GLOBALLY
|
2020-12-12 17:35:14 -05:00
|
|
|
using AK::decode_hex;
|
2021-04-13 15:49:05 -04:00
|
|
|
using AK::decode_hex_digit;
|
2020-12-12 17:35:14 -05:00
|
|
|
using AK::encode_hex;
|
2022-11-26 06:18:30 -05:00
|
|
|
#endif
|