Ready to write tests for Lipmaa linking

This commit is contained in:
Netscape Navigator 2020-04-11 09:53:22 -05:00
parent 71a93e91e7
commit d6742bb9c0
4 changed files with 13 additions and 8 deletions

11
dist/pigeon/lexer.rb vendored
View File

@ -24,7 +24,7 @@ module Pigeon
attr_reader :bundle_string, :scanner, :tokens
# TODO: Change all the `{40,90}` values in ::Lexer to real values
# TODO: Create regexes using string and Regexp.new() for cleaner regexes.
DEPTH_COUNT = /\d{1,7}/
NUMERIC = /\d{1,7}/
NULL_VALUE = /NONE/
FEED_VALUE = /@.{52}\.ed25519/
MESG_VALUE = /%.{52}\.sha256/
@ -43,7 +43,8 @@ module Pigeon
SEPERATOR = /\n/
AUTHOR = /author #{FEED_VALUE}\n/
DEPTH = /depth #{DEPTH_COUNT}\n/
DEPTH = /depth #{NUMERIC}\n/
LIPMAA = /lipmaa #{NUMERIC}\n/
PREV = /prev (#{MESG_VALUE}|#{NULL_VALUE})\n/
KIND = /kind #{ALPHANUMERICISH}\n/
BODY_ENTRY = /#{ALPHANUMERICISH}:#{ANY_VALUE}\n/
@ -82,6 +83,12 @@ module Pigeon
return
end
if scanner.scan(LIPMAA)
depth = scanner.matched.chomp.gsub("depth ", "").to_i
@tokens << [:LIPMAA, depth]
return
end
if scanner.scan(PREV)
prev = scanner.matched.chomp.gsub("prev ", "")
@tokens << [:PREV, prev]

View File

@ -2,7 +2,7 @@ require "digest"
module Pigeon
class Message
attr_reader :author, :kind, :body, :signature, :depth, :prev
attr_reader :author, :kind, :body, :signature, :depth, :lipmaa, :prev
class VerificationError < StandardError; end
@ -10,7 +10,7 @@ module Pigeon
# Store a message that someone (not the LocalIdentity)
# has authored.
def self.ingest(author:, body:, depth:, kind:, prev:, signature:)
def self.ingest(author:, body:, depth:, kind:, lipmaa:, prev:, signature:)
params = { author: RemoteIdentity.new(author),
kind: kind,
body: body,

View File

@ -19,6 +19,7 @@ module Pigeon
when :KIND then set(:kind, token.last)
when :DEPTH then set(:depth, token.last)
when :PREV then set(:prev, token.last)
when :LIPMAA then set(:lipmaa, token.last)
when :HEADER_END then set(:body, {})
when :BODY_ENTRY then set(token[1], token[2], @scratchpad[:body])
when :BODY_END then nil

View File

@ -92,10 +92,7 @@ RSpec.describe Pigeon::Message do
expect(m4.prev).to be
end
# Init LocalIdentity
# Get secret
# Create signing key
it "verifies accuracy of Lipmaa links"
it "verifies accuracy of signatures" do
# === Initial setup
Pigeon::LocalIdentity.current