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
Encoding.php
299 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace AmeliaVendor\ParagonIE\ConstantTime; |
| 5 | |
| 6 | use SensitiveParameter; |
| 7 | use TypeError; |
| 8 | /** |
| 9 | * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. |
| 10 | * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) |
| 11 | * |
| 12 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 13 | * of this software and associated documentation files (the "Software"), to deal |
| 14 | * in the Software without restriction, including without limitation the rights |
| 15 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 16 | * copies of the Software, and to permit persons to whom the Software is |
| 17 | * furnished to do so, subject to the following conditions: |
| 18 | * |
| 19 | * The above copyright notice and this permission notice shall be included in all |
| 20 | * copies or substantial portions of the Software. |
| 21 | * |
| 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 23 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 24 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 25 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 26 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 27 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 28 | * SOFTWARE. |
| 29 | */ |
| 30 | /** |
| 31 | * Class Encoding |
| 32 | * @package \ParagonIE\ConstantTime |
| 33 | */ |
| 34 | abstract class Encoding |
| 35 | { |
| 36 | /** |
| 37 | * RFC 4648 Base32 encoding |
| 38 | * |
| 39 | * @param string $str |
| 40 | * @return string |
| 41 | * @throws TypeError |
| 42 | */ |
| 43 | public static function base32Encode( |
| 44 | #[SensitiveParameter] |
| 45 | string $str |
| 46 | ): string |
| 47 | { |
| 48 | return Base32::encode($str); |
| 49 | } |
| 50 | /** |
| 51 | * RFC 4648 Base32 encoding |
| 52 | * |
| 53 | * @param string $str |
| 54 | * @return string |
| 55 | * @throws TypeError |
| 56 | */ |
| 57 | public static function base32EncodeUpper( |
| 58 | #[SensitiveParameter] |
| 59 | string $str |
| 60 | ): string |
| 61 | { |
| 62 | return Base32::encodeUpper($str); |
| 63 | } |
| 64 | /** |
| 65 | * RFC 4648 Base32 decoding |
| 66 | * |
| 67 | * @param string $str |
| 68 | * @return string |
| 69 | * @throws TypeError |
| 70 | */ |
| 71 | public static function base32Decode( |
| 72 | #[SensitiveParameter] |
| 73 | string $str |
| 74 | ): string |
| 75 | { |
| 76 | return Base32::decode($str); |
| 77 | } |
| 78 | /** |
| 79 | * RFC 4648 Base32 decoding |
| 80 | * |
| 81 | * @param string $str |
| 82 | * @return string |
| 83 | * @throws TypeError |
| 84 | */ |
| 85 | public static function base32DecodeUpper( |
| 86 | #[SensitiveParameter] |
| 87 | string $str |
| 88 | ): string |
| 89 | { |
| 90 | return Base32::decodeUpper($str); |
| 91 | } |
| 92 | /** |
| 93 | * RFC 4648 Base32 encoding |
| 94 | * |
| 95 | * @param string $str |
| 96 | * @return string |
| 97 | * @throws TypeError |
| 98 | */ |
| 99 | public static function base32HexEncode( |
| 100 | #[SensitiveParameter] |
| 101 | string $str |
| 102 | ): string |
| 103 | { |
| 104 | return Base32Hex::encode($str); |
| 105 | } |
| 106 | /** |
| 107 | * RFC 4648 Base32Hex encoding |
| 108 | * |
| 109 | * @param string $str |
| 110 | * @return string |
| 111 | * @throws TypeError |
| 112 | */ |
| 113 | public static function base32HexEncodeUpper( |
| 114 | #[SensitiveParameter] |
| 115 | string $str |
| 116 | ): string |
| 117 | { |
| 118 | return Base32Hex::encodeUpper($str); |
| 119 | } |
| 120 | /** |
| 121 | * RFC 4648 Base32Hex decoding |
| 122 | * |
| 123 | * @param string $str |
| 124 | * @return string |
| 125 | * @throws TypeError |
| 126 | */ |
| 127 | public static function base32HexDecode( |
| 128 | #[SensitiveParameter] |
| 129 | string $str |
| 130 | ): string |
| 131 | { |
| 132 | return Base32Hex::decode($str); |
| 133 | } |
| 134 | /** |
| 135 | * RFC 4648 Base32Hex decoding |
| 136 | * |
| 137 | * @param string $str |
| 138 | * @return string |
| 139 | * @throws TypeError |
| 140 | */ |
| 141 | public static function base32HexDecodeUpper( |
| 142 | #[SensitiveParameter] |
| 143 | string $str |
| 144 | ): string |
| 145 | { |
| 146 | return Base32Hex::decodeUpper($str); |
| 147 | } |
| 148 | /** |
| 149 | * RFC 4648 Base64 encoding |
| 150 | * |
| 151 | * @param string $str |
| 152 | * @return string |
| 153 | * @throws TypeError |
| 154 | */ |
| 155 | public static function base64Encode( |
| 156 | #[SensitiveParameter] |
| 157 | string $str |
| 158 | ): string |
| 159 | { |
| 160 | return Base64::encode($str); |
| 161 | } |
| 162 | /** |
| 163 | * RFC 4648 Base64 decoding |
| 164 | * |
| 165 | * @param string $str |
| 166 | * @return string |
| 167 | * @throws TypeError |
| 168 | */ |
| 169 | public static function base64Decode( |
| 170 | #[SensitiveParameter] |
| 171 | string $str |
| 172 | ): string |
| 173 | { |
| 174 | return Base64::decode($str); |
| 175 | } |
| 176 | /** |
| 177 | * Encode into Base64 |
| 178 | * |
| 179 | * Base64 character set "./[A-Z][a-z][0-9]" |
| 180 | * @param string $str |
| 181 | * @return string |
| 182 | * @throws TypeError |
| 183 | */ |
| 184 | public static function base64EncodeDotSlash( |
| 185 | #[SensitiveParameter] |
| 186 | string $str |
| 187 | ): string |
| 188 | { |
| 189 | return Base64DotSlash::encode($str); |
| 190 | } |
| 191 | /** |
| 192 | * Decode from base64 to raw binary |
| 193 | * |
| 194 | * Base64 character set "./[A-Z][a-z][0-9]" |
| 195 | * |
| 196 | * @param string $str |
| 197 | * @return string |
| 198 | * @throws \RangeException |
| 199 | * @throws TypeError |
| 200 | */ |
| 201 | public static function base64DecodeDotSlash( |
| 202 | #[SensitiveParameter] |
| 203 | string $str |
| 204 | ): string |
| 205 | { |
| 206 | return Base64DotSlash::decode($str); |
| 207 | } |
| 208 | /** |
| 209 | * Encode into Base64 |
| 210 | * |
| 211 | * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]" |
| 212 | * @param string $str |
| 213 | * @return string |
| 214 | * @throws TypeError |
| 215 | */ |
| 216 | public static function base64EncodeDotSlashOrdered( |
| 217 | #[SensitiveParameter] |
| 218 | string $str |
| 219 | ): string |
| 220 | { |
| 221 | return Base64DotSlashOrdered::encode($str); |
| 222 | } |
| 223 | /** |
| 224 | * Decode from base64 to raw binary |
| 225 | * |
| 226 | * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]" |
| 227 | * |
| 228 | * @param string $str |
| 229 | * @return string |
| 230 | * @throws \RangeException |
| 231 | * @throws TypeError |
| 232 | */ |
| 233 | public static function base64DecodeDotSlashOrdered( |
| 234 | #[SensitiveParameter] |
| 235 | string $str |
| 236 | ): string |
| 237 | { |
| 238 | return Base64DotSlashOrdered::decode($str); |
| 239 | } |
| 240 | /** |
| 241 | * Convert a binary string into a hexadecimal string without cache-timing |
| 242 | * leaks |
| 243 | * |
| 244 | * @param string $bin_string (raw binary) |
| 245 | * @return string |
| 246 | * @throws TypeError |
| 247 | */ |
| 248 | public static function hexEncode( |
| 249 | #[SensitiveParameter] |
| 250 | string $bin_string |
| 251 | ): string |
| 252 | { |
| 253 | return Hex::encode($bin_string); |
| 254 | } |
| 255 | /** |
| 256 | * Convert a hexadecimal string into a binary string without cache-timing |
| 257 | * leaks |
| 258 | * |
| 259 | * @param string $hex_string |
| 260 | * @return string (raw binary) |
| 261 | * @throws \RangeException |
| 262 | */ |
| 263 | public static function hexDecode( |
| 264 | #[SensitiveParameter] |
| 265 | string $hex_string |
| 266 | ): string |
| 267 | { |
| 268 | return Hex::decode($hex_string); |
| 269 | } |
| 270 | /** |
| 271 | * Convert a binary string into a hexadecimal string without cache-timing |
| 272 | * leaks |
| 273 | * |
| 274 | * @param string $bin_string (raw binary) |
| 275 | * @return string |
| 276 | * @throws TypeError |
| 277 | */ |
| 278 | public static function hexEncodeUpper( |
| 279 | #[SensitiveParameter] |
| 280 | string $bin_string |
| 281 | ): string |
| 282 | { |
| 283 | return Hex::encodeUpper($bin_string); |
| 284 | } |
| 285 | /** |
| 286 | * Convert a binary string into a hexadecimal string without cache-timing |
| 287 | * leaks |
| 288 | * |
| 289 | * @param string $bin_string (raw binary) |
| 290 | * @return string |
| 291 | */ |
| 292 | public static function hexDecodeUpper( |
| 293 | #[SensitiveParameter] |
| 294 | string $bin_string |
| 295 | ): string |
| 296 | { |
| 297 | return Hex::decode($bin_string); |
| 298 | } |
| 299 | } |