From 18a156a586e785c3be88b2caec0ff54bd42a5c10 Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Tue, 8 Nov 2022 18:12:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=81=D0=BB=D0=B5=D0=B4=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=20=D1=81?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=D0=B0=D1=80=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Dictionary/AbstractDictionary.php | 16 +++ src/Dictionary/AbstractTagsDictionary.php | 10 ++ src/Dictionary/AdditionalTagsDictionary.php | 40 ++++++++ src/Dictionary/IssuerTagsDictionary.php | 90 +---------------- src/Dictionary/OIDAwareTrait.php | 13 ++- src/Dictionary/RDNAwareTrait.php | 13 ++- src/Dictionary/StandardTagsDictionary.php | 82 ++++++++++++++++ src/Dictionary/SubjectTagsDictionary.php | 102 +------------------- src/Dictionary/TitleAwareTrait.php | 34 ++++--- 9 files changed, 189 insertions(+), 211 deletions(-) create mode 100755 src/Dictionary/AbstractTagsDictionary.php create mode 100755 src/Dictionary/AdditionalTagsDictionary.php create mode 100755 src/Dictionary/StandardTagsDictionary.php diff --git a/src/Dictionary/AbstractDictionary.php b/src/Dictionary/AbstractDictionary.php index 63030c0..a0004fd 100755 --- a/src/Dictionary/AbstractDictionary.php +++ b/src/Dictionary/AbstractDictionary.php @@ -29,4 +29,20 @@ abstract class AbstractDictionary implements DictionaryInterface return DictionaryItem::getItem($options); } + + public static function getMap() + { + $map = []; + + $class = static::class; + + do + { + array_push($map, ...$class::MAP); + } while (($class = get_parent_class($class)) != self::class); + + array_push($map, ...$class::MAP); + + return $map; + } } \ No newline at end of file diff --git a/src/Dictionary/AbstractTagsDictionary.php b/src/Dictionary/AbstractTagsDictionary.php new file mode 100755 index 0000000..e932f99 --- /dev/null +++ b/src/Dictionary/AbstractTagsDictionary.php @@ -0,0 +1,10 @@ + 'OGRN', + 'OID' => '1.2.643.100.1', + 'title' => 'ОГРН', + 'title_variants' => ['ОГРН'], + ], + [ + 'RDN' => 'SNILS', + 'OID' => '1.2.643.100.3', + 'title' => 'СНИЛС', + 'title_variants' => ['СНИЛС'], + ], + [ + 'RDN' => 'INN', + 'OID' => '1.2.643.3.131.1.1', + 'title' => 'ИНН', + 'title_variants' => ['ИННФЛ', 'ИНН ФЛ'], + ], + [ + 'RDN' => 'INNLE', + 'OID' => '1.2.643.100.4', + 'title' => 'ИНН организации', + 'title_variants' => ['ИННЮЛ', 'ИНН ЮЛ', 'INN LE'], + ], + [ + 'RDN' => 'OGRNIP', + 'OID' => '1.2.643.100.5', + 'title' => 'ОГРНИП', + 'title_variants' => ['ОГРНИП'], + ], + ]; +} \ No newline at end of file diff --git a/src/Dictionary/IssuerTagsDictionary.php b/src/Dictionary/IssuerTagsDictionary.php index abdf4c0..c078b62 100755 --- a/src/Dictionary/IssuerTagsDictionary.php +++ b/src/Dictionary/IssuerTagsDictionary.php @@ -2,103 +2,15 @@ namespace Webmasterskaya\CryptoPro\Dictionary; -class IssuerTagsDictionary extends AbstractDictionary implements RDNAwareInterface, TitleAwareInterface, OIDAwareInterface +class IssuerTagsDictionary extends AdditionalTagsDictionary { - use RDNAwareTrait; - use TitleAwareTrait; - use OIDAwareTrait; - protected const MAP = [ - [ - 'RDN' => 'UN', - 'OID' => '1.2.840.113549.1.9.2', - 'title' => 'Неструктурированное имя', - 'title_variants' => ['unstructuredName'], - ], [ 'RDN' => 'CN', 'OID' => '2.5.4.3', 'title' => 'Удостоверяющий центр', 'title_variants' => ['commonName'], ], - [ - 'RDN' => 'C', - 'OID' => '2.5.4.6', - 'title' => 'Страна', - 'title_variants' => ['countryName'], - ], - [ - 'RDN' => 'S', - 'OID' => '2.5.4.8', - 'title' => 'Регион', - 'title_variants' => ['ST', 'stateOrProvinceName'], - ], - [ - 'RDN' => 'STREET', - 'OID' => '2.5.4.9', - 'title' => 'Адрес', - 'title_variants' => ['streetAddress'], - ], - [ - 'RDN' => 'O', - 'OID' => '2.5.4.10', - 'title' => 'Компания', - 'title_variants' => ['organizationName'], - ], - [ - 'RDN' => 'OU', - 'OID' => '2.5.4.11', - 'title' => 'Тип', - 'title_variants' => ['organizationalUnitName'], - ], - [ - 'RDN' => 'T', - 'OID' => '2.5.4.12', - 'title' => 'Должность', - 'title_variants' => ['TITLE'], - ], - [ - 'RDN' => 'OGRN', - 'OID' => '1.2.643.100.1', - 'title' => 'ОГРН', - 'title_variants' => ['ОГРН'], - ], - [ - 'RDN' => 'OGRNIP', - 'OID' => '1.2.643.100.5', - 'title' => 'ОГРНИП', - 'title_variants' => ['ОГРНИП'], - ], - [ - 'RDN' => 'SNILS', - 'OID' => '1.2.643.100.3', - 'title' => 'СНИЛС', - 'title_variants' => ['СНИЛС'], - ], - [ - 'RDN' => 'INN', - 'OID' => '1.2.643.3.131.1.1', - 'title' => 'ИНН', - 'title_variants' => ['ИННФЛ', 'ИНН ФЛ'], - ], - [ - 'RDN' => 'INNLE', - 'OID' => '1.2.643.100.4', - 'title' => 'ИНН организации', - 'title_variants' => ['ИННЮЛ', 'ИНН ЮЛ', 'INN LE'], - ], - [ - 'RDN' => 'E', - 'OID' => '1.2.840.113549.1.9.1', - 'title' => 'Email', - 'title_variants' => ['email', 'emailAddress', 'pkcs9email'], - ], - [ - 'RDN' => 'L', - 'OID' => '2.5.4.7', - 'title' => 'Город', - 'title_variants' => ['localityName'], - ], ]; } \ No newline at end of file diff --git a/src/Dictionary/OIDAwareTrait.php b/src/Dictionary/OIDAwareTrait.php index abe8561..18278d6 100755 --- a/src/Dictionary/OIDAwareTrait.php +++ b/src/Dictionary/OIDAwareTrait.php @@ -8,9 +8,9 @@ trait OIDAwareTrait { $oid = mb_strtolower(trim($oid)); - $map = self::getOIDMap(); + $map = static::getOIDMap(); - return isset($map[$oid]) ? self::getResult($map[$oid]) : null; + return isset($map[$oid]) ? static::getResult($map[$oid]) : null; } protected static function getOIDMap() @@ -19,12 +19,15 @@ trait OIDAwareTrait if (!isset($OIDMap)) { - foreach (self::MAP as $row) + foreach (static::getMap() as $row) { if (isset($row['OID'])) { - $variant = mb_strtolower($row['OID']); - $OIDMap[$variant] = $row; + $variant = mb_strtolower($row['OID']); + if (!isset($OIDMap[$variant])) + { + $OIDMap[$variant] = $row; + } } } } diff --git a/src/Dictionary/RDNAwareTrait.php b/src/Dictionary/RDNAwareTrait.php index 70b5a07..bfa692c 100755 --- a/src/Dictionary/RDNAwareTrait.php +++ b/src/Dictionary/RDNAwareTrait.php @@ -8,9 +8,9 @@ trait RDNAwareTrait { $RDN = mb_strtolower(trim($RDN)); - $map = self::getRDNMap(); + $map = static::getRDNMap(); - return isset($map[$RDN]) ? self::getResult($map[$RDN]) : null; + return isset($map[$RDN]) ? static::getResult($map[$RDN]) : null; } protected static function getRDNMap() @@ -19,12 +19,15 @@ trait RDNAwareTrait if (!isset($RDNMap)) { - foreach (self::MAP as $row) + foreach (static::getMap() as $row) { if (isset($row['RDN'])) { - $variant = mb_strtolower($row['RDN']); - $RDNMap[$variant] = $row; + $variant = mb_strtolower($row['RDN']); + if (!isset($RDNMap[$variant])) + { + $RDNMap[$variant] = $row; + } } } } diff --git a/src/Dictionary/StandardTagsDictionary.php b/src/Dictionary/StandardTagsDictionary.php new file mode 100755 index 0000000..1357c35 --- /dev/null +++ b/src/Dictionary/StandardTagsDictionary.php @@ -0,0 +1,82 @@ + 'UN', + 'OID' => '1.2.840.113549.1.9.2', + 'title' => 'Неструктурированное имя', + 'title_variants' => ['unstructuredName'], + ], + [ + 'RDN' => 'CN', + 'OID' => '2.5.4.3', + 'title' => 'Удостоверяющий центр', + 'title_variants' => ['commonName'], + ], + [ + 'RDN' => 'SN', + 'OID' => '2.5.4.4', + 'title' => 'Фамилия', + 'title_variants' => ['surname'], + ], + [ + 'RDN' => 'G', + 'OID' => '2.5.4.42', + 'title' => 'Имя Отчество', + 'title_variants' => ['givenName', 'gn'], + ], + [ + 'RDN' => 'C', + 'OID' => '2.5.4.6', + 'title' => 'Страна', + 'title_variants' => ['countryName'], + ], + [ + 'RDN' => 'S', + 'OID' => '2.5.4.8', + 'title' => 'Регион', + 'title_variants' => ['ST', 'stateOrProvinceName'], + ], + [ + 'RDN' => 'L', + 'OID' => '2.5.4.7', + 'title' => 'Город', + 'title_variants' => ['localityName'], + ], + [ + 'RDN' => 'STREET', + 'OID' => '2.5.4.9', + 'title' => 'Адрес', + 'title_variants' => ['streetAddress'], + ], + [ + 'RDN' => 'O', + 'OID' => '2.5.4.10', + 'title' => 'Компания', + 'title_variants' => ['organizationName'], + ], + [ + 'RDN' => 'OU', + 'OID' => '2.5.4.11', + 'title' => 'Отдел/подразделение', + 'title_variants' => ['organizationalUnitName'], + ], + [ + 'RDN' => 'T', + 'OID' => '2.5.4.12', + 'title' => 'Должность', + 'title_variants' => ['TITLE'], + ], + [ + 'RDN' => 'E', + 'OID' => '1.2.840.113549.1.9.1', + 'title' => 'Email', + 'title_variants' => ['email', 'emailAddress', 'pkcs9email'], + ], + ]; +} \ No newline at end of file diff --git a/src/Dictionary/SubjectTagsDictionary.php b/src/Dictionary/SubjectTagsDictionary.php index a717ac3..fcf5702 100755 --- a/src/Dictionary/SubjectTagsDictionary.php +++ b/src/Dictionary/SubjectTagsDictionary.php @@ -2,115 +2,15 @@ namespace Webmasterskaya\CryptoPro\Dictionary; -class SubjectTagsDictionary extends AbstractDictionary implements RDNAwareInterface, TitleAwareInterface, OIDAwareInterface +class SubjectTagsDictionary extends AdditionalTagsDictionary { - use RDNAwareTrait; - use TitleAwareTrait; - use OIDAwareTrait; - protected const MAP = [ - [ - 'RDN' => 'UN', - 'OID' => '1.2.840.113549.1.9.2', - 'title' => 'Неструктурированное имя', - 'title_variants' => ['unstructuredName'], - ], [ 'RDN' => 'CN', 'OID' => '2.5.4.3', 'title' => 'Владелец', 'title_variants' => ['commonName'], ], - [ - 'RDN' => 'SN', - 'OID' => '2.5.4.4', - 'title' => 'Фамилия', - 'title_variants' => ['surname'], - ], - [ - 'RDN' => 'G', - 'OID' => '2.5.4.42', - 'title' => 'Имя Отчество', - 'title_variants' => ['givenName', 'gn'], - ], - [ - 'RDN' => 'C', - 'OID' => '2.5.4.6', - 'title' => 'Страна', - 'title_variants' => ['countryName'], - ], - [ - 'RDN' => 'S', - 'OID' => '2.5.4.8', - 'title' => 'Регион', - 'title_variants' => ['ST', 'stateOrProvinceName'], - ], - [ - 'RDN' => 'STREET', - 'OID' => '2.5.4.9', - 'title' => 'Адрес', - 'title_variants' => ['streetAddress'], - ], - [ - 'RDN' => 'O', - 'OID' => '2.5.4.10', - 'title' => 'Компания', - 'title_variants' => ['organizationName'], - ], - [ - 'RDN' => 'OU', - 'OID' => '2.5.4.11', - 'title' => 'Отдел/подразделение', - 'title_variants' => ['organizationalUnitName'], - ], - [ - 'RDN' => 'T', - 'OID' => '2.5.4.12', - 'title' => 'Должность', - 'title_variants' => ['TITLE'], - ], - [ - 'RDN' => 'OGRN', - 'OID' => '1.2.643.100.1', - 'title' => 'ОГРН', - 'title_variants' => ['ОГРН'], - ], - [ - 'RDN' => 'OGRNIP', - 'OID' => '1.2.643.100.5', - 'title' => 'ОГРНИП', - 'title_variants' => ['ОГРНИП'], - ], - [ - 'RDN' => 'SNILS', - 'OID' => '1.2.643.100.3', - 'title' => 'СНИЛС', - 'title_variants' => ['СНИЛС'], - ], - [ - 'RDN' => 'INN', - 'OID' => '1.2.643.3.131.1.1', - 'title' => 'ИНН', - 'title_variants' => ['ИННФЛ', 'ИНН ФЛ'], - ], - [ - 'RDN' => 'INNLE', - 'OID' => '1.2.643.100.4', - 'title' => 'ИНН организации', - 'title_variants' => ['ИННЮЛ', 'ИНН ЮЛ', 'INN LE'], - ], - [ - 'RDN' => 'E', - 'OID' => '1.2.840.113549.1.9.1', - 'title' => 'Email', - 'title_variants' => ['email', 'emailAddress', 'pkcs9email'], - ], - [ - 'RDN' => 'L', - 'OID' => '2.5.4.7', - 'title' => 'Город', - 'title_variants' => ['localityName'], - ], ]; } \ No newline at end of file diff --git a/src/Dictionary/TitleAwareTrait.php b/src/Dictionary/TitleAwareTrait.php index 9f58c60..c4ac911 100755 --- a/src/Dictionary/TitleAwareTrait.php +++ b/src/Dictionary/TitleAwareTrait.php @@ -8,9 +8,9 @@ trait TitleAwareTrait { $title = mb_strtolower(trim($title)); - $map = self::getTitleMap(); + $map = static::getTitleMap(); - return isset($map[$title]) ? self::getResult($map[$title]) : null; + return isset($map[$title]) ? static::getResult($map[$title]) : null; } protected static function getTitleMap() @@ -19,35 +19,47 @@ trait TitleAwareTrait if (!isset($titleMap)) { - foreach (self::MAP as $row) + foreach (static::getMap() as $row) { if (isset($row['title_variants'])) { if (is_string($row['title_variants'])) { - $variant = mb_strtolower($row['title_variants']); - $titleMap[$variant] = $row; + $variant = mb_strtolower($row['title_variants']); + if (!isset($titleMap[$variant])) + { + $titleMap[$variant] = $row; + } } else { foreach ($row['title_variants'] as $variant) { - $variant = mb_strtolower($variant); - $titleMap[$variant] = $row; + $variant = mb_strtolower($variant); + if (!isset($titleMap[$variant])) + { + $titleMap[$variant] = $row; + } } } } if (isset($row['title'])) { - $variant = mb_strtolower($row['title']); - $titleMap[$variant] = $row; + $variant = mb_strtolower($row['title']); + if (!isset($titleMap[$variant])) + { + $titleMap[$variant] = $row; + } } if (isset($row['RDN'])) { - $variant = mb_strtolower($row['RDN']); - $titleMap[$variant] = $row; + $variant = mb_strtolower($row['RDN']); + if (!isset($titleMap[$variant])) + { + $titleMap[$variant] = $row; + } } } }