<?php

namespace Buckhill\Yubico\tests\units\Modes\Yubikey;

require('vendor/autoload.php');

use Buckhill\Yubico\Modes\Yubikey\DecryptionResult;
use Buckhill\Yubico\Modes\Yubikey\OTP;
use mageekguy\atoum;

class Yubikey extends atoum
{
    public function testOTPDecryption()
    {
        $otp = $this->getOTP();
        $key = $this->getYubikey();

        $this
            ->given($decrypted = $otp->decrypt($key))
            ->then
                ->object($decrypted)->isInstanceOf(DecryptionResult::class)
                ->integer($decrypted->getUseCounter())->isEqualTo(1)
                ->integer($decrypted->getSessionCounter())->isEqualTo(0)
                ->string($decrypted->getPrivateId())->isEqualTo('f8d18d05c13a')
        ;
    }


    /**
     * @return \Buckhill\Yubico\Modes\Yubikey\Yubikey
     */
    protected function getYubikey()
    {
        $public_id = 'vv jc lr cj le fn';
        $private_id = 'f8 d1 8d 05 c1 3a';
        $key = 'e7 7d a9 46 de f1 2b b9 47 cd a0 f7 a4 45 cf 84';

        return new \Buckhill\Yubico\Modes\Yubikey\Yubikey($public_id, $private_id, $key);
    }


    /**
     * @return OTP
     */
    protected function getOTP()
    {
        return new OTP('vvjclrcjlefnjvrldcflfrrjitjlnrtebuklrhlvtujn');
    }
}