diff --git a/README.md b/README.md index 615a416..6ffe764 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`. - [X] Run Flog / Flay and friends to find duplications. Will aid in port to other languages. - [X] Make all methods private except those required for the CLI. - [ ] Add Lipmaa links like the Bamboo folks do. + - [ ] Verification of `depth` and `lipmaa` may need a re-look to support partial verification. - [ ] Make the switch to LevelDB, RocksDB, [UNQLite](https://unqlite.org/features.html) or similar (currently using Ruby PStore). - [ ] Make CLI names consistent with API names. Eg: find vs. read. - [ ] Create regexes in ::Lexer using strings and Regexp.new() for cleaner regexes. diff --git a/dist/pigeon.rb b/dist/pigeon.rb index a9869f0..131284f 100644 --- a/dist/pigeon.rb +++ b/dist/pigeon.rb @@ -87,7 +87,7 @@ module Pigeon # The original lipmaa function returns -1 for 0 # but that does not mesh well with our serialization # scheme. Comments welcome on this one. - return 0 if n == 0 # Prevent -1 return value. + return 0 if n < 1 # Prevent -1, division by zero etc.. m, po3, x = 1, 3, n # find k such that (3^k - 1)/2 >= n diff --git a/dist/pigeon/lexer.rb b/dist/pigeon/lexer.rb index 11bc23d..e4534c4 100644 --- a/dist/pigeon/lexer.rb +++ b/dist/pigeon/lexer.rb @@ -100,7 +100,7 @@ module Pigeon end if scanner.scan(LIPMAA) - depth = scanner.matched.chomp.gsub("depth ", "").to_i + depth = scanner.matched.chomp.gsub("lipmaa ", "").to_i @tokens << [:LIPMAA, depth] return end diff --git a/dist/pigeon/message.rb b/dist/pigeon/message.rb index ae8b756..eaa80a4 100644 --- a/dist/pigeon/message.rb +++ b/dist/pigeon/message.rb @@ -39,7 +39,7 @@ module Pigeon def save! return store.read_message(multihash) if store.message?(multihash) - verify_depth_prev_and_depth + verify_counted_fields verify_signature self.freeze store.save_message(self) @@ -53,11 +53,14 @@ module Pigeon end end - def verify_depth_prev_and_depth + def verify_counted_fields count = store.get_message_count_for(author.multihash) expected_prev = store.get_message_by_depth(author.multihash, count - 1) || Pigeon::NOTHING assert("depth", count, depth) - assert("lipmaa", Helpers.lipmaa(count), lipmaa) + # TODO: Re-visit this. Our current verification method + # is probably too strict and won't allow for partial + # verification of feeds. + assert("lipmaa", Helpers.lipmaa(depth), lipmaa) assert("prev", prev, expected_prev) end @@ -83,16 +86,6 @@ module Pigeon @signature = signature end - def params - { author: @author, - kind: @kind, - body: @body, - depth: @depth, - prev: @prev, - lipmaa: @lipmaa, - signature: @signature } - end - def template MessageSerializer.new(self) end diff --git a/spec/pigeon/helpers_spec.rb b/spec/pigeon/helpers_spec.rb index 7457648..f66d3f1 100644 --- a/spec/pigeon/helpers_spec.rb +++ b/spec/pigeon/helpers_spec.rb @@ -1,4 +1,23 @@ RSpec.describe Pigeon::Helpers do + it "creates lipmalinks" do + [ + [-1, 0], + [0, 0], + [1, 0], + [2, 1], + [3, 2], + [4, 1], + [5, 4], + [6, 5], + [7, 6], + [8, 4], + [13, 4], + ].map do |(input, expected)| + actual = Pigeon::Helpers.lipmaa(input) + expect(actual).to eq(expected) + end + end + it "handles Crockford Base 32 values" do 10.times do raw_bytes = SecureRandom.random_bytes(32) diff --git a/spec/pigeon/message_spec.rb b/spec/pigeon/message_spec.rb index 2548ffd..0fb60aa 100644 --- a/spec/pigeon/message_spec.rb +++ b/spec/pigeon/message_spec.rb @@ -50,6 +50,7 @@ RSpec.describe Pigeon::Message do "kind unit_test", "prev NONE", "depth 0", + "lipmaa 0", "", "a:\"bar\"", "b:&CHHABX8Q9D9Q0BY2BBZ6FA7SMAFNE9GGMSDTZVZZC9TK2N9F15QG.sha256",