Skip to content

Commit

Permalink
Directory: fix broken directory-signature parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
aarani committed Apr 23, 2023
1 parent 41cfb4a commit 7b574cd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion NOnion.Tests/Directory-Samples/NetworkStatus.json

Large diffs are not rendered by default.

30 changes: 22 additions & 8 deletions NOnion/Directory/NetworkStatusDocument.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace NOnion.Directory

open System
open System.Text

open NOnion
open NOnion.Utility
Expand Down Expand Up @@ -216,14 +215,16 @@ type RouterStatusEntry =

type DirectorySignature =
{
Algorithm: Option<string>
Identity: Option<string>
Digest: Option<string>
Signature: Option<string>
}

static member Empty =
{
DirectorySignature.Identity = None
DirectorySignature.Algorithm = None
Identity = None
Digest = None
Signature = None
}
Expand Down Expand Up @@ -252,12 +253,25 @@ type DirectorySignature =
| "directory-signature" when state.Identity = None ->
lines.Dequeue() |> ignore<string>

innerParse
{ state with
DirectorySignature.Identity = readWord() |> Some
Digest = readWord() |> Some
Signature = readBlock String.Empty |> Some
}
let algs = [ "sha1"; "sha256" ]
let maybeAlg = readWord()

if Seq.contains maybeAlg algs then
innerParse
{ state with
DirectorySignature.Algorithm = maybeAlg |> Some
Identity = readWord() |> Some
Digest = readWord() |> Some
Signature = readBlock String.Empty |> Some
}
else
innerParse
{ state with
DirectorySignature.Algorithm = "sha1" |> Some
Identity = maybeAlg |> Some
Digest = readWord() |> Some
Signature = readBlock String.Empty |> Some
}
| "directory-signature" when state.Identity <> None -> state
| _ -> state

Expand Down

0 comments on commit 7b574cd

Please sign in to comment.