Base32.php
7 months ago
Base32Hex.php
7 months ago
Base64.php
7 months ago
Base64DotSlash.php
7 months ago
Base64DotSlashOrdered.php
7 months ago
Base64UrlSafe.php
7 months ago
Binary.php
7 months ago
EncoderInterface.php
7 months ago
Encoding.php
7 months ago
Hex.php
7 months ago
RFC4648.php
7 months ago
RFC4648.php
206 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace AmeliaVendor\ParagonIE\ConstantTime; |
| 5 | |
| 6 | use TypeError; |
| 7 | /** |
| 8 | * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. |
| 9 | * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) |
| 10 | * |
| 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
| 17 | * |
| 18 | * The above copyright notice and this permission notice shall be included in all |
| 19 | * copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 27 | * SOFTWARE. |
| 28 | */ |
| 29 | /** |
| 30 | * Class RFC4648 |
| 31 | * |
| 32 | * This class conforms strictly to the RFC |
| 33 | * |
| 34 | * @package \ParagonIE\ConstantTime |
| 35 | */ |
| 36 | abstract class RFC4648 |
| 37 | { |
| 38 | /** |
| 39 | * RFC 4648 Base64 encoding |
| 40 | * |
| 41 | * "foo" -> "Zm9v" |
| 42 | * |
| 43 | * @param string $str |
| 44 | * @return string |
| 45 | * |
| 46 | * @throws TypeError |
| 47 | */ |
| 48 | public static function base64Encode( |
| 49 | #[\SensitiveParameter] |
| 50 | string $str |
| 51 | ): string |
| 52 | { |
| 53 | return Base64::encode($str); |
| 54 | } |
| 55 | /** |
| 56 | * RFC 4648 Base64 decoding |
| 57 | * |
| 58 | * "Zm9v" -> "foo" |
| 59 | * |
| 60 | * @param string $str |
| 61 | * @return string |
| 62 | * |
| 63 | * @throws TypeError |
| 64 | */ |
| 65 | public static function base64Decode( |
| 66 | #[\SensitiveParameter] |
| 67 | string $str |
| 68 | ): string |
| 69 | { |
| 70 | return Base64::decode($str, true); |
| 71 | } |
| 72 | /** |
| 73 | * RFC 4648 Base64 (URL Safe) encoding |
| 74 | * |
| 75 | * "foo" -> "Zm9v" |
| 76 | * |
| 77 | * @param string $str |
| 78 | * @return string |
| 79 | * |
| 80 | * @throws TypeError |
| 81 | */ |
| 82 | public static function base64UrlSafeEncode( |
| 83 | #[\SensitiveParameter] |
| 84 | string $str |
| 85 | ): string |
| 86 | { |
| 87 | return Base64UrlSafe::encode($str); |
| 88 | } |
| 89 | /** |
| 90 | * RFC 4648 Base64 (URL Safe) decoding |
| 91 | * |
| 92 | * "Zm9v" -> "foo" |
| 93 | * |
| 94 | * @param string $str |
| 95 | * @return string |
| 96 | * |
| 97 | * @throws TypeError |
| 98 | */ |
| 99 | public static function base64UrlSafeDecode( |
| 100 | #[\SensitiveParameter] |
| 101 | string $str |
| 102 | ): string |
| 103 | { |
| 104 | return Base64UrlSafe::decode($str, true); |
| 105 | } |
| 106 | /** |
| 107 | * RFC 4648 Base32 encoding |
| 108 | * |
| 109 | * "foo" -> "MZXW6===" |
| 110 | * |
| 111 | * @param string $str |
| 112 | * @return string |
| 113 | * |
| 114 | * @throws TypeError |
| 115 | */ |
| 116 | public static function base32Encode( |
| 117 | #[\SensitiveParameter] |
| 118 | string $str |
| 119 | ): string |
| 120 | { |
| 121 | return Base32::encodeUpper($str); |
| 122 | } |
| 123 | /** |
| 124 | * RFC 4648 Base32 encoding |
| 125 | * |
| 126 | * "MZXW6===" -> "foo" |
| 127 | * |
| 128 | * @param string $str |
| 129 | * @return string |
| 130 | * |
| 131 | * @throws TypeError |
| 132 | */ |
| 133 | public static function base32Decode( |
| 134 | #[\SensitiveParameter] |
| 135 | string $str |
| 136 | ): string |
| 137 | { |
| 138 | return Base32::decodeUpper($str, true); |
| 139 | } |
| 140 | /** |
| 141 | * RFC 4648 Base32-Hex encoding |
| 142 | * |
| 143 | * "foo" -> "CPNMU===" |
| 144 | * |
| 145 | * @param string $str |
| 146 | * @return string |
| 147 | * |
| 148 | * @throws TypeError |
| 149 | */ |
| 150 | public static function base32HexEncode( |
| 151 | #[\SensitiveParameter] |
| 152 | string $str |
| 153 | ): string |
| 154 | { |
| 155 | return Base32::encodeUpper($str); |
| 156 | } |
| 157 | /** |
| 158 | * RFC 4648 Base32-Hex decoding |
| 159 | * |
| 160 | * "CPNMU===" -> "foo" |
| 161 | * |
| 162 | * @param string $str |
| 163 | * @return string |
| 164 | * |
| 165 | * @throws TypeError |
| 166 | */ |
| 167 | public static function base32HexDecode( |
| 168 | #[\SensitiveParameter] |
| 169 | string $str |
| 170 | ): string |
| 171 | { |
| 172 | return Base32::decodeUpper($str, true); |
| 173 | } |
| 174 | /** |
| 175 | * RFC 4648 Base16 decoding |
| 176 | * |
| 177 | * "foo" -> "666F6F" |
| 178 | * |
| 179 | * @param string $str |
| 180 | * @return string |
| 181 | * |
| 182 | * @throws TypeError |
| 183 | */ |
| 184 | public static function base16Encode( |
| 185 | #[\SensitiveParameter] |
| 186 | string $str |
| 187 | ): string |
| 188 | { |
| 189 | return Hex::encodeUpper($str); |
| 190 | } |
| 191 | /** |
| 192 | * RFC 4648 Base16 decoding |
| 193 | * |
| 194 | * "666F6F" -> "foo" |
| 195 | * |
| 196 | * @param string $str |
| 197 | * @return string |
| 198 | */ |
| 199 | public static function base16Decode( |
| 200 | #[\SensitiveParameter] |
| 201 | string $str |
| 202 | ): string |
| 203 | { |
| 204 | return Hex::decode($str, true); |
| 205 | } |
| 206 | } |