diff --git a/CHANGELOG.md b/CHANGELOG.md
index 080063c..a5f20dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [[v0.4.0](https://github.com/The-FireHub-Project/Runtime/compare/v0.3.3...v0.4.0)] – 2026-10-29
+
+### Added
+* Introduced a new `Encoding` class in `Runtime` by @dieselxxx
+
## [[v0.3.3](https://github.com/The-FireHub-Project/Runtime/compare/v0.3.2...v0.3.3)] – 2026-10-12
### Added
diff --git a/README.md b/README.md
index 7e5addf..c09857d 100644
--- a/README.md
+++ b/README.md
@@ -7,12 +7,12 @@
PHP Runtime Foundation
@@ -22,25 +22,46 @@
/>
-[](https://github.com/The-FireHub-Project/Runtime/actions/workflows/PHPStan.yml)
-[](https://github.com/The-FireHub-Project/Runtime/actions/workflows/PHPUnit.yml)
-[](https://app.codecov.io/gh/The-FireHub-Project/Runtime/tree/develop)
-
-
+
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+ * Data to encode. + *
+ * + * @return string Base64-encoded data. + */ + public static function base64Encode (string $data):string { + + return base64_encode($data); + + } + + /** + * ### Decode Base64-encoded data + * @since 1.0.0 + * + * @param string $data+ * Encoded data. + *
+ * + * @return string|false Decoded data, or false on failure. + */ + public static function base64Decode (string $data):string|false { + + return base64_decode($data, true); + + } + + /** + * ### Encode binary data as hexadecimal + * @since 1.0.0 + * + * @param string $data+ * Binary data. + *
+ * + * @return string Hexadecimal representation. + */ + public static function hexEncode (string $data):string { + + return bin2hex($data); + + } + + /** + * ### Decode hexadecimal data + * @since 1.0.0 + * + * @param string $data+ * Hexadecimal representation. + *
+ * + * @return string|false Decoded data, or false on invalid input. + */ + public static function hexDecode (string $data):string|false { + + return hex2bin($data); + + } + + /** + * ### Encode data using quoted-printable + * @since 1.0.0 + * + * @param string $data+ * Data to encode. + *
+ * + * @return string Quoted-printable encoded data. + */ + public static function quotedPrintableEncode (string $data):string { + + return quoted_printable_encode($data); + + } + + /** + * ### Decode quoted-printable data + * @since 1.0.0 + * + * @param string $data+ * Encoded data. + *
+ * + * @return string Decoded data. + */ + public static function quotedPrintableDecode (string $data):string { + + return quoted_printable_decode($data); + + } + + /** + * ### Encode data using uuencoding + * @since 1.0.0 + * + * @param string $data+ * Data to encode. + *
+ * + * @return string Uuencoded data. + */ + public static function uuEncode (string $data):string { + + return convert_uuencode($data); + + } + + /** + * ### Decode uuencoded data + * @since 1.0.0 + * + * @param string $data+ * Encoded data. + *
+ * + * @return string|false Decoded data, or false on failure. + */ + public static function uuDecode (string $data):string|false { + + return convert_uudecode($data); + + } + +} diff --git a/tests/Unit/EncodingTest.php b/tests/Unit/EncodingTest.php new file mode 100644 index 0000000..ebb066d --- /dev/null +++ b/tests/Unit/EncodingTest.php @@ -0,0 +1,159 @@ + + * @copyright 2026-present The FireHub Project - All rights reserved + * @license https://opensource.org/license/Apache-2-0 Apache License, Version 2.0 + * + * @php-version >=7.4 + * @package Runtime\Tests + */ + +namespace FireHub\Tests\Runtime\Unit; + +use FireHub\Testing\FireHubTestCase; +use FireHub\Runtime\Encoding; +use PHPUnit\Framework\Attributes\ { + CoversClass, DataProviderExternal, Depends, Group, Small, TestWith +}; + +/** + * ### Test binary-to-text encoding runtime utilities + * @since 1.0.0 + */ +#[Small] +#[Group('src')] +#[CoversClass(Encoding::class)] +final class EncodingTest extends FireHubTestCase { + + /** + * @since 1.0.0 + * + * @param string $expected + * @param string $data + * + * @return void + */ + #[TestWith(['', ''])] + #[TestWith(['ZmlyZWh1Yg==', 'firehub'])] + #[TestWith(['AP8=', "\x00\xFF"])] + public function testBase64Encode (string $expected, string $data):void { + + self::assertSame($expected, Encoding::base64Encode($data)); + + } + + /** + * @since 1.0.0 + * + * @param string $expected + * @param string $data + * + * @return void + */ + #[TestWith(['', ''])] + #[TestWith(['firehub', 'ZmlyZWh1Yg=='])] + #[TestWith(["\x00\xFF", 'AP8='])] + public function testBase64Decode (string $expected, string $data):void { + + self::assertSame($expected, Encoding::base64Decode($data)); + + } + + /** + * @since 1.0.0 + * + * @return void + */ + public function testBase64DecodeStrictness ():void { + + self::assertFalse(Encoding::base64Decode('Zmly!ZWh1Yg==')); + + } + + /** + * @since 1.0.0 + * + * @param string $expected + * @param string $data + * + * @return void + */ + #[TestWith(['', ''])] + #[TestWith(['66697265687562', 'firehub'])] + #[TestWith(['00ff', "\x00\xFF"])] + public function testHexEncode (string $expected, string $data):void { + + self::assertSame($expected, Encoding::hexEncode($data)); + + } + + /** + * @since 1.0.0 + * + * @param string $expected + * @param string $data + * + * @return void + */ + #[TestWith(['', ''])] + #[TestWith(['firehub', '66697265687562'])] + #[TestWith(["\x00\xFF", '00FF'])] + public function testHexDecode (string $expected, string $data):void { + + self::assertSame($expected, Encoding::hexDecode($data)); + + } + + /** + * @since 1.0.0 + * + * @param string $expected + * @param string $data + * + * @return void + */ + #[TestWith(['firehub', 'firehub'])] + #[TestWith(['=00=FF', "\x00\xFF"])] + public function testQuotedPrintableEncode (string $expected, string $data):void { + + self::assertSame($expected, Encoding::quotedPrintableEncode($data)); + + } + + /** + * @since 1.0.0 + * + * @param string $expected + * @param string $data + * + * @return void + */ + #[TestWith(['firehub', 'firehub'])] + #[TestWith(["\x00\xFF", '=00=FF'])] + #[TestWith(['Hello World', "Hello=\r\n World"])] + public function testQuotedPrintableDecode (string $expected, string $data):void { + + self::assertSame($expected, Encoding::quotedPrintableDecode($data)); + + } + + /** + * @since 1.0.0 + * + * @return void + */ + public function testUuEncodeDecode ():void { + + $data = "FireHub\x00\xFF"; + + $encoded = Encoding::uuEncode($data); + + self::assertSame(convert_uuencode($data), $encoded); + self::assertSame($data, Encoding::uuDecode($encoded)); + + } + +} \ No newline at end of file