CoreFiles by mySites.guru
U2FPublicKey.php47 lines, 1,453 bytes, from Joomla_5.3.2-Stable-Full_Package.zip
Raw History Compare with 5.3.1
md5
f150854620f719978afee14b28b1f060
sha1
6ad0d3da12b5c3ec8728853a390fba141bf86606
sha256
ea758eef6dd389595eee65e87f159c4a654672a9df2c8e4091c777996065e06e
<?php

declare(strict_types=1);

namespace Webauthn;

use CBOR\ByteStringObject;
use CBOR\MapItem;
use CBOR\MapObject;
use CBOR\NegativeIntegerObject;
use CBOR\UnsignedIntegerObject;
use Cose\Algorithms;
use Cose\Key\Ec2Key;

class U2FPublicKey
{
    public static function isU2FKey(string $publicKey): bool
    {
        return $publicKey[0] === "\x04" && mb_strlen($publicKey, '8bit') === 65;
    }

    public static function convertToCoseKey(string $publicKey): string
    {
        return MapObject::create([
            MapItem::create(
                UnsignedIntegerObject::create(Ec2Key::TYPE),
                UnsignedIntegerObject::create(Ec2Key::TYPE_EC2)
            ),
            MapItem::create(
                UnsignedIntegerObject::create(Ec2Key::ALG),
                NegativeIntegerObject::create(Algorithms::COSE_ALGORITHM_ES256)
            ),
            MapItem::create(
                NegativeIntegerObject::create(Ec2Key::DATA_CURVE),
                UnsignedIntegerObject::create(Ec2Key::CURVE_P256)
            ),
            MapItem::create(
                NegativeIntegerObject::create(Ec2Key::DATA_X),
                ByteStringObject::create(mb_substr($publicKey, 1, 32, '8bit'))
            ),
            MapItem::create(
                NegativeIntegerObject::create(Ec2Key::DATA_Y),
                ByteStringObject::create(mb_substr($publicKey, 33, null, '8bit'))
            ),
        ])->__toString();
    }
}

The same content is in 157 releases, Joomla 5.0.0-alpha1 to 6.2.1. See them all, or every version of this file.