Code Duplication    Length = 29-29 lines in 2 locations

src/library/sodium_compat/src/Crypto.php 1 location

@@ 651-679 (lines=29) @@
648
     * @return string
649
     * @throws RangeException
650
     */
651
    public static function generichash($message, $key = '', $outlen = 32)
652
    {
653
        // This ensures that ParagonIE_Sodium_Core_BLAKE2b::$iv is initialized
654
        ParagonIE_Sodium_Core_BLAKE2b::pseudoConstructor();
655
656
        $k = null;
657
        if (!empty($key)) {
658
            /** @var SplFixedArray $k */
659
            $k = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($key);
660
            if ($k->count() > ParagonIE_Sodium_Core_BLAKE2b::KEYBYTES) {
661
                throw new RangeException('Invalid key size');
662
            }
663
        }
664
665
        /** @var SplFixedArray $in */
666
        $in = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($message);
667
668
        /** @var SplFixedArray $ctx */
669
        $ctx = ParagonIE_Sodium_Core_BLAKE2b::init($k, $outlen);
670
        ParagonIE_Sodium_Core_BLAKE2b::update($ctx, $in, $in->count());
671
672
        /** @var SplFixedArray $out */
673
        $out = new SplFixedArray($outlen);
674
        $out = ParagonIE_Sodium_Core_BLAKE2b::finish($ctx, $out);
675
676
        /** @var array<int, int> */
677
        $outArray = $out->toArray();
678
        return ParagonIE_Sodium_Core_Util::intArrayToString($outArray);
679
    }
680
681
    /**
682
     * Finalize a BLAKE2b hashing context, returning the hash.

src/library/sodium_compat/src/Crypto32.php 1 location

@@ 636-664 (lines=29) @@
633
     * @return string
634
     * @throws RangeException
635
     */
636
    public static function generichash($message, $key = '', $outlen = 32)
637
    {
638
        // This ensures that ParagonIE_Sodium_Core32_BLAKE2b::$iv is initialized
639
        ParagonIE_Sodium_Core32_BLAKE2b::pseudoConstructor();
640
641
        $k = null;
642
        if (!empty($key)) {
643
            /** @var SplFixedArray $k */
644
            $k = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray($key);
645
            if ($k->count() > ParagonIE_Sodium_Core32_BLAKE2b::KEYBYTES) {
646
                throw new RangeException('Invalid key size');
647
            }
648
        }
649
650
        /** @var SplFixedArray $in */
651
        $in = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray($message);
652
653
        /** @var SplFixedArray $ctx */
654
        $ctx = ParagonIE_Sodium_Core32_BLAKE2b::init($k, $outlen);
655
        ParagonIE_Sodium_Core32_BLAKE2b::update($ctx, $in, $in->count());
656
657
        /** @var SplFixedArray $out */
658
        $out = new SplFixedArray($outlen);
659
        $out = ParagonIE_Sodium_Core32_BLAKE2b::finish($ctx, $out);
660
661
        /** @var array<int, int> */
662
        $outArray = $out->toArray();
663
        return ParagonIE_Sodium_Core32_Util::intArrayToString($outArray);
664
    }
665
666
    /**
667
     * Finalize a BLAKE2b hashing context, returning the hash.