Code Duplication    Length = 25-25 lines in 2 locations

src/library/sodium_compat/src/Compat.php 2 locations

@@ 785-809 (lines=25) @@
782
     * @throws Error
783
     * @throws TypeError
784
     */
785
    public static function crypto_box_keypair_from_secretkey_and_publickey($secretKey, $publicKey)
786
    {
787
        /* Type checks: */
788
        ParagonIE_Sodium_Core_Util::declareScalarType($secretKey, 'string', 1);
789
        ParagonIE_Sodium_Core_Util::declareScalarType($publicKey, 'string', 2);
790
791
        /* Input validation: */
792
        if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_BOX_SECRETKEYBYTES) {
793
            throw new Error('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.');
794
        }
795
        if (ParagonIE_Sodium_Core_Util::strlen($publicKey) !== self::CRYPTO_BOX_PUBLICKEYBYTES) {
796
            throw new Error('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.');
797
        }
798
799
        if (self::isPhp72OrGreater()) {
800
            return sodium_crypto_box_keypair_from_secretkey_and_publickey($secretKey, $publicKey);
801
        }
802
        if (self::use_fallback('crypto_box_keypair_from_secretkey_and_publickey')) {
803
            return call_user_func('\\Sodium\\crypto_box_keypair_from_secretkey_and_publickey', $secretKey, $publicKey);
804
        }
805
        if (PHP_INT_SIZE === 4) {
806
            return ParagonIE_Sodium_Crypto32::box_keypair_from_secretkey_and_publickey($secretKey, $publicKey);
807
        }
808
        return ParagonIE_Sodium_Crypto::box_keypair_from_secretkey_and_publickey($secretKey, $publicKey);
809
    }
810
811
    /**
812
     * Decrypt a message previously encrypted with crypto_box().
@@ 1731-1755 (lines=25) @@
1728
     * @throws Error
1729
     * @throws TypeError
1730
     */
1731
    public static function crypto_sign_open($signedMessage, $publicKey)
1732
    {
1733
        /* Type checks: */
1734
        ParagonIE_Sodium_Core_Util::declareScalarType($signedMessage, 'string', 1);
1735
        ParagonIE_Sodium_Core_Util::declareScalarType($publicKey, 'string', 2);
1736
1737
        /* Input validation: */
1738
        if (ParagonIE_Sodium_Core_Util::strlen($signedMessage) < self::CRYPTO_SIGN_BYTES) {
1739
            throw new Error('Argument 1 must be at least CRYPTO_SIGN_BYTES long.');
1740
        }
1741
        if (ParagonIE_Sodium_Core_Util::strlen($publicKey) !== self::CRYPTO_SIGN_PUBLICKEYBYTES) {
1742
            throw new Error('Argument 2 must be CRYPTO_SIGN_PUBLICKEYBYTES long.');
1743
        }
1744
1745
        if (self::isPhp72OrGreater()) {
1746
            return sodium_crypto_sign_open($signedMessage, $publicKey);
1747
        }
1748
        if (self::use_fallback('crypto_sign_open')) {
1749
            return call_user_func('\\Sodium\\crypto_sign_open', $signedMessage, $publicKey);
1750
        }
1751
        if (PHP_INT_SIZE === 4) {
1752
            return ParagonIE_Sodium_Crypto32::sign_open($signedMessage, $publicKey);
1753
        }
1754
        return ParagonIE_Sodium_Crypto::sign_open($signedMessage, $publicKey);
1755
    }
1756
1757
    /**
1758
     * Generate a new random Ed25519 keypair.