[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare(strict_types=1); 4 5 /* 6 * The MIT License (MIT) 7 * 8 * Copyright (c) 2014-2019 Spomky-Labs 9 * 10 * This software may be modified and distributed under the terms 11 * of the MIT license. See the LICENSE file for details. 12 */ 13 14 namespace Webauthn; 15 16 use Assert\Assertion; 17 use Base64Url\Base64Url; 18 use InvalidArgumentException; 19 use Webauthn\TokenBinding\TokenBinding; 20 21 class CollectedClientData 22 { 23 /** 24 * @var string 25 */ 26 private $rawData; 27 28 /** 29 * @var array 30 */ 31 private $data; 32 33 /** 34 * @var string 35 */ 36 private $type; 37 38 /** 39 * @var string 40 */ 41 private $challenge; 42 43 /** 44 * @var string 45 */ 46 private $origin; 47 48 /** 49 * @var array|null 50 */ 51 private $tokenBinding; 52 53 public function __construct(string $rawData, array $data) 54 { 55 $this->type = $this->findData($data, 'type'); 56 $this->challenge = $this->findData($data, 'challenge', true, true); 57 $this->origin = $this->findData($data, 'origin'); 58 $this->tokenBinding = $this->findData($data, 'tokenBinding', false); 59 $this->rawData = $rawData; 60 $this->data = $data; 61 } 62 63 public static function createFormJson(string $data): self 64 { 65 $rawData = Base64Url::decode($data); 66 $json = json_decode($rawData, true); 67 Assertion::eq(JSON_ERROR_NONE, json_last_error(), 'Invalid collected client data'); 68 Assertion::isArray($json, 'Invalid collected client data'); 69 70 return new self($rawData, $json); 71 } 72 73 public function getType(): string 74 { 75 return $this->type; 76 } 77 78 public function getChallenge(): string 79 { 80 return $this->challenge; 81 } 82 83 public function getOrigin(): string 84 { 85 return $this->origin; 86 } 87 88 public function getTokenBinding(): ?TokenBinding 89 { 90 return null === $this->tokenBinding ? null : TokenBinding::createFormArray($this->tokenBinding); 91 } 92 93 public function getRawData(): string 94 { 95 return $this->rawData; 96 } 97 98 /** 99 * @return string[] 100 */ 101 public function all(): array 102 { 103 return array_keys($this->data); 104 } 105 106 public function has(string $key): bool 107 { 108 return \array_key_exists($key, $this->data); 109 } 110 111 /** 112 * @return mixed 113 */ 114 public function get(string $key) 115 { 116 if (!$this->has($key)) { 117 throw new InvalidArgumentException(sprintf('The key "%s" is missing', $key)); 118 } 119 120 return $this->data[$key]; 121 } 122 123 /** 124 * @return mixed|null 125 */ 126 private function findData(array $json, string $key, bool $isRequired = true, bool $isB64 = false) 127 { 128 if (!\array_key_exists($key, $json)) { 129 if ($isRequired) { 130 throw new InvalidArgumentException(sprintf('The key "%s" is missing', $key)); 131 } 132 133 return; 134 } 135 136 return $isB64 ? Base64Url::decode($json[$key]) : $json[$key]; 137 } 138 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |