malczak / hashids Goto Github PK
View Code? Open in Web Editor NEWHashids, ported for Swift (http://www.hashids.org)
License: MIT License
Hashids, ported for Swift (http://www.hashids.org)
License: MIT License
Why is iOS 11 the minimum deployment target? A lot of the apps have at least 10 as the deployment target or even lower, I don't see why updating it to Swift 4 made this a requirement.
Trouble getting it to work on swift 5, probably because only 0.3.0 is on cocoapods?
If yes, how do we get started on contributing? A brief guide on how to setup this repo in Xcode so we can start coding and running tests would be great.
I tried cloning the repo but after that, there's no .xcodproj or .xcworkspace file to work with.
Compatible to Swift 1.2
The following code will crash.
let hashOfMaxInt64 = "jvNx4BjM5KYjv" // untrusted input
let hashids = Hashids(salt: "this is my salt")
let values = hashids.decode64(hashOfMaxInt64) // ๐ฅ Crash
A simple hash of Int64.max
will crash when attempting to decode because the double overflows the integer during decoding. Personally, I think the Double
-> Int
constructor should return an optional since it can fail as this ends up being a foot-gun in an otherwise safe language.
Because of how hashids work, it is impossible to know ahead of time if a given input is safe without first trying to decode it. If you run this library on a web server on untrusted input, you are at risk of a crash and should patch immediately.
I have opened a PR to address this, but considering this repo has been inactive, I don't expect it to be merged. I will leave my fork with the fix up for others to use.
Would be awesome if we could import this into our projects using Swift PM instead of cocoapods.
Will you add new encodeHex/decodeHex functions? In JS version it's supported..
If I pass a int parameter larger than 2,147,483,647 in iphone 5 32bit device, it will crash for Int is 32bit.
Is this an issue?
let hashids = Hashids(salt: "icaslntrigresnisteet", minHashLength: 32, alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890");
hash = hashids.encode(1, 2, 8)
In Swift this yields:
n1EOZmo3bKArd9YcphPd742kWewMpvPR
In PHP (specifically with Laravel config)
'main' => [
'salt' => 'icaslntrigresnisteet',
'length' => 32,
'alphabet' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890',
],
PHP yields:
n1EOZmo3bKArd9YCpHPd742kWewMpvPR
Notice that the C and H are lowercase in Swift but uppercase in PHP. This is really concerning... if I can't trust that the hashes are the same in Swift and PHP then I can't use this at all.
The 1, 2, 8
is just one example. I've tried many other numbers and the hash is always incorrect. It's always the two letters in position 16 and 18 that are lowercase and should be uppercase.
this swift library can't find cocoapods.org
update doesn't conform to other hashids libraries ... try using generated hash from swift and decode with php or js library of hashids.
the encode does something else then the other version of hashids.org libraries.
the decode encodes the swift 3 version and the version of other libraries from hashids.org
Unlike the Java and JS equivalents this implementation doesn't appear to support empty salts:
let hashids = Hashids(salt:"", minHashLength: 20)
throws:
Fatal error: Remainder of division by zero
Looks like this is going to need some parts refactored for Swift 2 support.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.