public static function fromAlgorithmIdentifier(PBEAlgorithmIdentifier $algo,
        Crypto $crypto = null): PBEScheme
    {
        $crypto = $crypto ?: Crypto::getDefault();
        if ($algo instanceof PBES1AlgorithmIdentifier) {
            return new PBES1($algo->hashFunc(), $algo->blockCipher(),
                $algo->salt(), $algo->iterationCount(), $crypto);
        }
        if ($algo instanceof PBES2AlgorithmIdentifier) {
            $prf = PRF::fromAlgorithmIdentifier(
                $algo->kdfAlgorithmIdentifier()->prfAlgorithmIdentifier());
            return new PBES2($prf, $algo->esAlgorithmIdentifier(), $algo->salt(),
                $algo->iterationCount(), $crypto);
        }
        throw new \UnexpectedValueException(
            sprintf("No encryption scheme for %s algorithm.", $algo->name()));
    }