Skip to content

Commit a0ea1aa

Browse files
committed
Added isValidShare?
1 parent dd3d71e commit a0ea1aa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/sssa.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,26 @@ def self.combine(shares)
8686

8787
return @util.merge_ints(secret)
8888
end
89+
90+
# Takes in a given candidate to check if it is a valid secret
91+
#
92+
# Requirements:
93+
# Length multiple of 88
94+
# Can decode each 44 character block as base64
95+
#
96+
# Returns only true/false
97+
def self.isValidShare?(candidate)
98+
if candidate.size % 88 != 0
99+
return false
100+
end
101+
102+
count = candidate.size / 44
103+
for j in 0..count
104+
part = candidate[j*44, (j+1)*44]
105+
decode = self.from_base64(part)
106+
if decode < 0 || decode > self.prime
107+
return false
108+
end
109+
end
110+
end
89111
end

0 commit comments

Comments
 (0)