Giter Site home page Giter Site logo

cuid's Introduction

Hi there ๐Ÿ‘‹

Dead Skull

Ghosts ๐Ÿ‘ป from the past ๐Ÿ“š are everywhere,
hauting the only one left future โŒš
-- in which time is frozen ๐Ÿฅถ forever.


Stats ๐Ÿงช

Profile Stats Top Langs

cuid's People

Contributors

marcoonroad avatar

Stargazers

 avatar

Watchers

 avatar  avatar

cuid's Issues

Cuid standard is deprecated.

Due to security concerns (which also exist in database auto-increment ids, uuid/guid, and most other id standrads), the Cuid standard is now deprecated in favor of Cuid2.

Fingerprint environment variable allows arbitrary non-hexadecimal fingerprints.

The problem lies around the following piece of code:

	if FINGERPRINT then
		return pad (FINGERPRINT, BLOCK_SIZE)
	end
...

Here, FINGERPRINT might contain invalid characters (that is, characters out of the hexadecimal value range).

The solution is to catch such thing on tests. Our test must validate if the CUID fields contain valid hexadecimal characters.

๐Ÿ˜ƒ

Discrepancy between base conversions

The library contains the maximum number representable under base-36 by 4 digits (i.e, 1679616 = 36 ** 4), but our internal machinery only converts to base-16 by 4 digits values (the maximum representable value here is 65536 = 16 ** 4).

The following pieces of code contain such problems, the former regarding base-36:

local DISCRETE_VALUES = 1679616 -- 36 ^ BLOCK_SIZE --

And this latter regarding base-16:

local function to_hex (number)
	return string.format ("%x", math.floor (number))
end

We need to extend the range of conversion to match the range of representation, therefore, we need
a new function called to_base36 instead of to_hex here.

We're not obliged to stick to base-36 following CUID specification, but I want to comply how much possible with that.

Slugs & API-level custom fingerprints.

The next release (planned to be v0.4-1) will bring the following features:

  • API-level custom fingerprints (rather than just sole environment variables).
  • Slugs (shorter CUIDs) for URL disambiguation, for instance.

The planned API-level fingerprint customization is the following:

local cuid = require 'cuid'
local fingerprint_text = "It's me, Mario!"
local id = cuid.generate (fingerprint_text)

Where the cuid.generate accepts fingerprint_text as an optional argument.
So, it could be called as well:

local id = cuid.generate ( )

And thus, no prior/previous API is broken (in the case, v0.3-1). This default case for CUID
generation will try to figure out a fingerprint out of the LUA_CUID_FINGERPRINT
environment variable, if defined. Otherwise, there's an internal machinery (a.k.a black magic)
which final users (library clients) must not rely upon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.