Code Duplication    Length = 21-21 lines in 6 locations

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

@@ 859-879 (lines=21) @@
856
     * @throws Error
857
     * @throws TypeError
858
     */
859
    public static function crypto_box_publickey($keypair)
860
    {
861
        /* Type checks: */
862
        ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 1);
863
864
        /* Input validation: */
865
        if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) {
866
            throw new Error('Argument 1 must be CRYPTO_BOX_KEYPAIRBYTES long.');
867
        }
868
869
        if (self::isPhp72OrGreater()) {
870
            return sodium_crypto_box_publickey($keypair);
871
        }
872
        if (self::use_fallback('crypto_box_publickey')) {
873
            return call_user_func('\\Sodium\\crypto_box_publickey', $keypair);
874
        }
875
        if (PHP_INT_SIZE === 4) {
876
            return ParagonIE_Sodium_Crypto32::box_publickey($keypair);
877
        }
878
        return ParagonIE_Sodium_Crypto::box_publickey($keypair);
879
    }
880
881
    /**
882
     * Calculate the X25519 public key from a given X25519 secret key.
@@ 889-909 (lines=21) @@
886
     * @throws Error
887
     * @throws TypeError
888
     */
889
    public static function crypto_box_publickey_from_secretkey($secretKey)
890
    {
891
        /* Type checks: */
892
        ParagonIE_Sodium_Core_Util::declareScalarType($secretKey, 'string', 1);
893
894
        /* Input validation: */
895
        if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_BOX_SECRETKEYBYTES) {
896
            throw new Error('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.');
897
        }
898
899
        if (self::isPhp72OrGreater()) {
900
            return sodium_crypto_box_publickey_from_secretkey($secretKey);
901
        }
902
        if (self::use_fallback('crypto_box_publickey_from_secretkey')) {
903
            return call_user_func('\\Sodium\\crypto_box_publickey_from_secretkey', $secretKey);
904
        }
905
        if (PHP_INT_SIZE === 4) {
906
            return ParagonIE_Sodium_Crypto32::box_publickey_from_secretkey($secretKey);
907
        }
908
        return ParagonIE_Sodium_Crypto::box_publickey_from_secretkey($secretKey);
909
    }
910
911
    /**
912
     * Extract the secret key from a crypto_box keypair.
@@ 919-939 (lines=21) @@
916
     * @throws Error
917
     * @throws TypeError
918
     */
919
    public static function crypto_box_secretkey($keypair)
920
    {
921
        /* Type checks: */
922
        ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 1);
923
924
        /* Input validation: */
925
        if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) {
926
            throw new Error('Argument 1 must be CRYPTO_BOX_KEYPAIRBYTES long.');
927
        }
928
929
        if (self::isPhp72OrGreater()) {
930
            return sodium_crypto_box_secretkey($keypair);
931
        }
932
        if (self::use_fallback('crypto_box_secretkey')) {
933
            return call_user_func('\\Sodium\\crypto_box_secretkey', $keypair);
934
        }
935
        if (PHP_INT_SIZE === 4) {
936
            return ParagonIE_Sodium_Crypto32::box_secretkey($keypair);
937
        }
938
        return ParagonIE_Sodium_Crypto::box_secretkey($keypair);
939
    }
940
941
    /**
942
     * Generate an X25519 keypair from a seed.
@@ 1812-1832 (lines=21) @@
1809
     * @throws Error
1810
     * @throws TypeError
1811
     */
1812
    public static function crypto_sign_publickey($keypair)
1813
    {
1814
        /* Type checks: */
1815
        ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 1);
1816
1817
        /* Input validation: */
1818
        if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_SIGN_KEYPAIRBYTES) {
1819
            throw new Error('Argument 1 must be CRYPTO_SIGN_KEYPAIRBYTES long.');
1820
        }
1821
1822
        if (self::isPhp72OrGreater()) {
1823
            return sodium_crypto_sign_publickey($keypair);
1824
        }
1825
        if (self::use_fallback('crypto_sign_publickey')) {
1826
            return call_user_func('\\Sodium\\crypto_sign_publickey', $keypair);
1827
        }
1828
        if (PHP_INT_SIZE === 4) {
1829
            return ParagonIE_Sodium_Core32_Ed25519::publickey($keypair);
1830
        }
1831
        return ParagonIE_Sodium_Core_Ed25519::publickey($keypair);
1832
    }
1833
1834
    /**
1835
     * Calculate an Ed25519 public key from an Ed25519 secret key.
@@ 1842-1862 (lines=21) @@
1839
     * @throws Error
1840
     * @throws TypeError
1841
     */
1842
    public static function crypto_sign_publickey_from_secretkey($secretKey)
1843
    {
1844
        /* Type checks: */
1845
        ParagonIE_Sodium_Core_Util::declareScalarType($secretKey, 'string', 1);
1846
1847
        /* Input validation: */
1848
        if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_SIGN_SECRETKEYBYTES) {
1849
            throw new Error('Argument 1 must be CRYPTO_SIGN_SECRETKEYBYTES long.');
1850
        }
1851
1852
        if (self::isPhp72OrGreater()) {
1853
            return sodium_crypto_sign_publickey_from_secretkey($secretKey);
1854
        }
1855
        if (self::use_fallback('crypto_sign_publickey_from_secretkey')) {
1856
            return call_user_func('\\Sodium\\crypto_sign_publickey_from_secretkey', $secretKey);
1857
        }
1858
        if (PHP_INT_SIZE === 4) {
1859
            return ParagonIE_Sodium_Core32_Ed25519::publickey_from_secretkey($secretKey);
1860
        }
1861
        return ParagonIE_Sodium_Core_Ed25519::publickey_from_secretkey($secretKey);
1862
    }
1863
1864
    /**
1865
     * Extract an Ed25519 secret key from an Ed25519 keypair.
@@ 1872-1892 (lines=21) @@
1869
     * @throws Error
1870
     * @throws TypeError
1871
     */
1872
    public static function crypto_sign_secretkey($keypair)
1873
    {
1874
        /* Type checks: */
1875
        ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 1);
1876
1877
        /* Input validation: */
1878
        if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_SIGN_KEYPAIRBYTES) {
1879
            throw new Error('Argument 1 must be CRYPTO_SIGN_KEYPAIRBYTES long.');
1880
        }
1881
1882
        if (self::isPhp72OrGreater()) {
1883
            return sodium_crypto_sign_secretkey($keypair);
1884
        }
1885
        if (self::use_fallback('crypto_sign_secretkey')) {
1886
            return call_user_func('\\Sodium\\crypto_sign_secretkey', $keypair);
1887
        }
1888
        if (PHP_INT_SIZE === 4) {
1889
            return ParagonIE_Sodium_Core32_Ed25519::secretkey($keypair);
1890
        }
1891
        return ParagonIE_Sodium_Core_Ed25519::secretkey($keypair);
1892
    }
1893
1894
    /**
1895
     * Calculate the Ed25519 signature of a message and return ONLY the signature.