health-cards icon indicating copy to clipboard operation
health-cards copied to clipboard

Clarify about QR numeric encoding - is it unique to Smart Health Cards?

Open jtara opened this issue 3 years ago • 3 comments

Doing one of the hardest things in software development - naming! And I don't know what to call my little function that decodes the numeric QR code value to Base64.

Is this encoding scheme some standard, borrowed from somewhere else, or unique to Smart Health Cards?

If it is some standard, would be good to mention it, and then we know how to look for already-existing optimized implementations, rather than having the re-invent the wheel. (As I just have in Ruby...)

It is simple, easy to implement in any language (but perhaps one shouldn't have to) but, at least... what is it called?

It's a bit of a Caesar Cipher, but of course that's not it's purpose.

As it is, I'm going to turn it into a Ruby String extension, with the awkward named shc_qrnum_to_b64 Which MIGHT be appropriate, if it is unique to Smart Health Cards.

Yea, I should subclass string perhaps (me lazy) - then the function becomes just to_b64 but I still have the conundrum as to what to call the class.

TL;DR Does the algorithm have a name? If so, can it get into the docs? If not, clarify it's not a common algorithm and is unique to Smart Health Cards.

jtara avatar Jul 15 '21 18:07 jtara

Agreed, naming is hard :-)

  • In our example generator we call our encoding function toNumericQr (though this is purely an internal detail) https://github.com/smart-on-fhir/health-cards/blob/main/generate-examples/src/index.ts#L172-L182

  • In the spec we just talk about "Encoding Chunks as QR codes". The algorithm isn't an external standard and doesn't have a name. We could add an explicit statement to this effect (though in practice, I think that's kind of the default; if it was externally defined we'd mention this in https://spec.smarthealth.cards/#references)

And I don't know what to call my little function that decodes the numeric QR code value to Base64

I have a nit-pick here: technically you're not turning a numeric QR into a B64 string -- you're turning it into a JWS, which includes three base64 strings separated by .s (the presence of . in the output means the output itself isn't valid base64 content).

jmandel avatar Jul 15 '21 21:07 jmandel

Thank for pointing out the b64 misnomer, sure it's a jws.

I'm ultimately planning on using ruby-jws, right now just using some utility functions in it, and hacked-together ad-hoc code to decode and verify using bits of ruby-jws and bits of openssl. ruby-jws didn't anticipate the compressed payload, and so can't verify the jws (as opposed to the signature) without some way to tap into the decode chain. I will see if I wind up with something useful to contribute back to ruby-jws.

from_shc_qr_numeric might be a good name. To String, it's just a String. The representation would seem to have use beyond Smart Health Cards, though.

jtara avatar Jul 15 '21 23:07 jtara

Depending on your goals, consider https://rubygems.org/gems/health_cards for ruby, too.

jmandel avatar Jul 16 '21 04:07 jmandel