Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Twingly URL tools.
* `Twingly::URL.parse` - Returns one or more `Twingly::URL` instance
* `twingly/url/hasher` - Generate URL hashes suitable for primary keys
* `Twingly::URL::Hasher.taskdb_hash(url)` - MD5 hexdigest
* `Twingly::URL::Hasher.documentdb_hash(url)` - SHA256 unsigned long, native endian digest
* `Twingly::URL::Hasher.autopingdb_hash(url)` - SHA256 64-bit signed, native endian digest
* `Twingly::URL::Hasher.documentdb_hash(url)` - SHA256 unsigned 64-bit little-endian digest
* `Twingly::URL::Hasher.autopingdb_hash(url)` - SHA256 64-bit signed little-endian digest
* `twingly/url/utilities` - Utilities to work with URLs
* `Twingly::URL::Utilities.extract_valid_urls` - Returns Array of valid `Twingly::URL`
* `twingly/url/extended` - Extended normalization and hashing, stripping blacklisted query and matrix parameters as well as the fragment.
Expand Down
4 changes: 2 additions & 2 deletions lib/twingly/url/hasher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def taskdb_hash(url)
end

def documentdb_hash(url)
SHA256_DIGEST.digest(url).unpack("L!")[0]
SHA256_DIGEST.digest(url).unpack("Q<")[0]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix unless this PR is rejected.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the README and matching spec descriptions to specify fixed 64-bit little-endian values, preserving signedness. Commit: 67897b1.

end

def autopingdb_hash(url)
SHA256_DIGEST.digest(url).unpack("q")[0]
SHA256_DIGEST.digest(url).unpack("q<")[0]
end
Comment on lines 26 to 28

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use this method anywhere, and the same with the taskdb_hash method above. We should probably also rename documentdb_hash to something better, as none of the old databases they're referencing exists anymore.

Nothing we need to do here though, just thought I would mention it.

end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/twingly/url/hasher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
end

describe ".documentdb_hash" do
it "returns a SHA256 unsigned long, native endian digest" do
it "returns a SHA256 unsigned 64-bit little-endian digest" do
expect(Twingly::URL::Hasher.documentdb_hash("http://blog.twingly.com/")).to eq 15340752212397415993
end
end

describe ".autopingdb_hash" do
let(:expected) { -3105991861312135623 }

it "returns a SHA256 64-bit signed, native endian digest" do
it "returns a SHA256 64-bit signed little-endian digest" do
expect(Twingly::URL::Hasher.autopingdb_hash("http://blog.twingly.com/")).to eq expected
end
end
Expand Down