Code Duplication    Length = 19-20 lines in 2 locations

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

@@ 1518-1536 (lines=19) @@
1515
     * @throws Error
1516
     * @throws TypeError
1517
     */
1518
    public static function crypto_secretbox_xchacha20poly1305($plaintext, $nonce, $key)
1519
    {
1520
        /* Type checks: */
1521
        ParagonIE_Sodium_Core_Util::declareScalarType($plaintext, 'string', 1);
1522
        ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
1523
        ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3);
1524
1525
        /* Input validation: */
1526
        if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_SECRETBOX_NONCEBYTES) {
1527
            throw new Error('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.');
1528
        }
1529
        if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_SECRETBOX_KEYBYTES) {
1530
            throw new Error('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.');
1531
        }
1532
        if (PHP_INT_SIZE === 4) {
1533
            return ParagonIE_Sodium_Crypto32::secretbox_xchacha20poly1305($plaintext, $nonce, $key);
1534
        }
1535
        return ParagonIE_Sodium_Crypto::secretbox_xchacha20poly1305($plaintext, $nonce, $key);
1536
    }
1537
    /**
1538
     * Decrypts a message previously encrypted with crypto_secretbox_xchacha20poly1305().
1539
     *
@@ 1547-1566 (lines=20) @@
1544
     * @throws Error
1545
     * @throws TypeError
1546
     */
1547
    public static function crypto_secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key)
1548
    {
1549
        /* Type checks: */
1550
        ParagonIE_Sodium_Core_Util::declareScalarType($ciphertext, 'string', 1);
1551
        ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
1552
        ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3);
1553
1554
        /* Input validation: */
1555
        if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_SECRETBOX_NONCEBYTES) {
1556
            throw new Error('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.');
1557
        }
1558
        if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_SECRETBOX_KEYBYTES) {
1559
            throw new Error('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.');
1560
        }
1561
1562
        if (PHP_INT_SIZE === 4) {
1563
            return ParagonIE_Sodium_Crypto32::secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key);
1564
        }
1565
        return ParagonIE_Sodium_Crypto::secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key);
1566
    }
1567
1568
    /**
1569
     * Calculates a SipHash-2-4 hash of a message for a given key.