summaryrefslogtreecommitdiffstats
path: root/lib/blocks.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2021-01-12 19:22:07 -0500
committerrsiddharth <s@ricketyspace.net>2021-01-12 19:22:07 -0500
commit5e83546a0b02acd88d205e4cd99b14a4fc4636e0 (patch)
tree9ddc8912337fadcc9431e82371791e4fae3e8217 /lib/blocks.go
parent2c05dfb2204a23c1a19ccdf97b03ea599ea8951d (diff)
lib: add HasConsecutiveMatchingBlocks
Diffstat (limited to 'lib/blocks.go')
-rw-r--r--lib/blocks.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/blocks.go b/lib/blocks.go
index a82feb2..76f39d6 100644
--- a/lib/blocks.go
+++ b/lib/blocks.go
@@ -72,6 +72,20 @@ func CipherUsesECB(bs []byte) []byte {
return nil
}
+// Returns (index, found); where `index` is the starting index of the
+// consecutive matching blocks; `index` is -1 when consective matching
+// blocks are not found.
+func HasConsecutiveMatchingBlocks(bs []byte, bsize int) (int, bool) {
+ blocks := BreakIntoBlocks(bs, bsize)
+
+ for i := 0; i < len(blocks)-1; i++ {
+ if BlocksEqual(blocks[i], blocks[i+1]) {
+ return i * bsize, true
+ }
+ }
+ return -1, false
+}
+
func hasMatchingBlock(id int, blocks [][]byte) bool {
for i := 0; i < len(blocks); i++ {
if i == id {