Subversion Repositories php_utils

Rev

Rev 37 | Rev 40 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37 Rev 38
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * ISO/IEC 7816-5 Application Identifier decoder for PHP
4
 * ISO/IEC 7816-5 Application Identifier decoder for PHP
5
 * Copyright 2022 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2022 Daniel Marschall, ViaThinkSoft
6
 * Version 2022-08-17
6
 * Version 2022-08-19
7
 *
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
10
 * You may obtain a copy of the License at
11
 *
11
 *
Line 371... Line 371...
371
        }
371
        }
372
        if (strlen($aid)%2 == 1) $aid_hf .= '_';
372
        if (strlen($aid)%2 == 1) $aid_hf .= '_';
373
        $aid_hf = rtrim($aid_hf);
373
        $aid_hf = rtrim($aid_hf);
374
        $out[] = array("$aid", "ISO/IEC 7816-5 Application Identifier (AID)");
374
        $out[] = array("$aid", "ISO/IEC 7816-5 Application Identifier (AID)");
375
        $out[] = array('', "> $aid_hf <");
375
        $out[] = array('', "> $aid_hf <");
-
 
376
        $out[] = array('', c_literal_hexstr($aid));
376
 
377
 
377
        if ((strlen($aid) == 32) && (substr($aid,-2) == 'FF')) {
378
        if ((strlen($aid) == 32) && (substr($aid,-2) == 'FF')) {
378
                // https://www.kartenbezogene-identifier.de/content/dam/kartenbezogene_identifier/de/PDFs/RID_Antrag_2006.pdf
379
                // https://www.kartenbezogene-identifier.de/content/dam/kartenbezogene_identifier/de/PDFs/RID_Antrag_2006.pdf
379
                // writes: "Wenn die PIX aus 11 Bytes besteht, muss das letzte Byte einen Hexadezimal-Wert ungleich ´FF´ aufweisen (´FF´ ist von ISO reserviert)."
380
                // writes: "Wenn die PIX aus 11 Bytes besteht, muss das letzte Byte einen Hexadezimal-Wert ungleich ´FF´ aufweisen (´FF´ ist von ISO reserviert)."
380
                // https://www.etsi.org/deliver/etsi_ts/101200_101299/101220/07.03.00_60/ts_101220v070300p.pdf
381
                // https://www.etsi.org/deliver/etsi_ts/101200_101299/101220/07.03.00_60/ts_101220v070300p.pdf
Line 445... Line 446...
445
                        } else {
446
                        } else {
446
                                $asi = substr($iin,1);
447
                                $asi = substr($iin,1);
447
                                $asn = $asi;
448
                                $asn = $asi;
448
                        }
449
                        }
449
                        $out[] = array("$pad$asn", 'Assigned number'.($asi=='' ? ' (missing)' : ''));
450
                        $out[] = array("$pad$asn", 'Assigned number'.($asi=='' ? ' (missing)' : ''));
-
 
451
                        if ($asi!='') $out[] = array('', c_literal_hexstr($asi));
450
                        $pad .= str_repeat(' ',strlen($asn));
452
                        $pad .= str_repeat(' ',strlen($asn));
451
 
453
 
452
                        $padded_iin = $iin;
454
                        $padded_iin = $iin;
453
                        if (strlen($iin)%2 != 0) {
455
                        if (strlen($iin)%2 != 0) {
454
                                $odd_padding = substr($aid,strlen($iin),1);
456
                                $odd_padding = substr($aid,strlen($iin),1);
Line 491... Line 493...
491
                                if ($pix == '') {
493
                                if ($pix == '') {
492
                                        $out[] = "Proprietary application identifier extension (PIX) missing";
494
                                        $out[] = "Proprietary application identifier extension (PIX) missing";
493
                                        $out[] = "Warning: If PIX is available, FF delimites RID/IIN from PIX. Since PIX is empty, consider removing FF."; // not sure if this is an error or not
495
                                        $out[] = "Warning: If PIX is available, FF delimites RID/IIN from PIX. Since PIX is empty, consider removing FF."; // not sure if this is an error or not
494
                                } else {
496
                                } else {
495
                                        $out[] = array($pad.$pix, "Proprietary application identifier extension (PIX)");
497
                                        $out[] = array($pad.$pix, "Proprietary application identifier extension (PIX)");
-
 
498
                                        $out[] = array('', c_literal_hexstr($pix));
496
                                }
499
                                }
497
                        }
500
                        }
498
 
501
 
499
                        return $out;
502
                        return $out;
500
                }
503
                }
Line 513... Line 516...
513
                $asn = str_pad($asi,9,'_',STR_PAD_RIGHT);
516
                $asn = str_pad($asi,9,'_',STR_PAD_RIGHT);
514
 
517
 
515
                $out[] = array("$rid", "Registered Application Provider Identifier (RID)");
518
                $out[] = array("$rid", "Registered Application Provider Identifier (RID)");
516
                $out[] = array("$category", "Category $category: International registration");
519
                $out[] = array("$category", "Category $category: International registration");
517
                $out[] = array(" $asn", 'Assigned number, BCD recommended'.($asi=='' ? ' (missing)' : ''));
520
                $out[] = array(" $asn", 'Assigned number, BCD recommended'.($asi=='' ? ' (missing)' : ''));
-
 
521
                if ($asi!='') $out[] = array('', c_literal_hexstr($asi));
518
                if ($pix == '') {
522
                if ($pix == '') {
519
                        $out[] = "Proprietary application identifier extension (PIX) missing";
523
                        $out[] = "Proprietary application identifier extension (PIX) missing";
520
                } else {
524
                } else {
521
                        $out[] = array(str_pad($pix,strlen($aid),' ',STR_PAD_LEFT), "Proprietary application identifier extension (PIX)");
525
                        $out[] = array(str_pad($pix,strlen($aid),' ',STR_PAD_LEFT), "Proprietary application identifier extension (PIX)");
-
 
526
                        $out[] = array('', c_literal_hexstr($pix));
522
                }
527
                }
523
 
528
 
524
                return $out;
529
                return $out;
525
        }
530
        }
526
 
531
 
Line 545... Line 550...
545
                } else {
550
                } else {
546
                        $country_name = isset($iso3166[$country]) ? $iso3166[$country] : 'Unknown country';
551
                        $country_name = isset($iso3166[$country]) ? $iso3166[$country] : 'Unknown country';
547
                        $out[] = array(" ".str_pad($country,3,'_',STR_PAD_RIGHT), "ISO/IEC 3166-1 Numeric Country code : $country ($country_name)");
552
                        $out[] = array(" ".str_pad($country,3,'_',STR_PAD_RIGHT), "ISO/IEC 3166-1 Numeric Country code : $country ($country_name)");
548
                }
553
                }
549
                $out[] = array("    $asn", 'Assigned number, BCD recommended'.($asi=='' ? ' (missing)' : ''));
554
                $out[] = array("    $asn", 'Assigned number, BCD recommended'.($asi=='' ? ' (missing)' : ''));
-
 
555
                if ($asi!='') $out[] = array('', c_literal_hexstr($asi));
550
                if ($pix == '') {
556
                if ($pix == '') {
551
                        $out[] = "Proprietary application identifier extension (PIX) missing";
557
                        $out[] = "Proprietary application identifier extension (PIX) missing";
552
                } else {
558
                } else {
553
                        $out[] = array(str_pad($pix,strlen($aid),' ',STR_PAD_LEFT), "Proprietary application identifier extension (PIX)");
559
                        $out[] = array(str_pad($pix,strlen($aid),' ',STR_PAD_LEFT), "Proprietary application identifier extension (PIX)");
-
 
560
                        $out[] = array('', c_literal_hexstr($pix));
554
                }
561
                }
555
 
562
 
556
                return $out;
563
                return $out;
557
        }
564
        }
558
 
565
 
Line 564... Line 571...
564
                $pix = substr($aid,1);
571
                $pix = substr($aid,1);
565
                if ($pix == '') {
572
                if ($pix == '') {
566
                        $out[] = "Proprietary application identifier extension (PIX) missing";
573
                        $out[] = "Proprietary application identifier extension (PIX) missing";
567
                } else {
574
                } else {
568
                        $out[] = array(' '.$pix, "Proprietary application identifier extension (PIX)");
575
                        $out[] = array(' '.$pix, "Proprietary application identifier extension (PIX)");
-
 
576
                        $out[] = array('', c_literal_hexstr($pix));
569
                }
577
                }
570
                return $out;
578
                return $out;
571
        }
579
        }
572
 
580
 
573
        // Category 'B', 'C', and 'E' are reserved
581
        // Category 'B', 'C', and 'E' are reserved
574
        $out[] = array("$category", "Category $category: ILLEGAL USAGE / RESERVED");
582
        $out[] = array("$category", "Category $category: ILLEGAL USAGE / RESERVED");
575
        if (strlen($aid) > 1) {
583
        if (strlen($aid) > 1) {
-
 
584
                $aid_ = substr($aid,1);
576
                $out[] = array(" ".substr($aid,1), "Unknown composition");
585
                $out[] = array(" ".$aid_, "Unknown composition");
-
 
586
                $out[] = array('', c_literal_hexstr($aid_));
577
        }
587
        }
578
        return $out;
588
        return $out;
579
}
589
}
580
 
590
 
581
/* --- Small extra function: not part of the decoder --- */
591
/* --- Small extra function: not part of the decoder --- */