Check if a variable value is base64 #66

Open
opened 2019-02-10 04:34:59 -06:00 by CleanHit · 2 comments
CleanHit commented 2019-02-10 04:34:59 -06:00 (Migrated from github.com)

Is there a way to check with this code if some variable value was coded in base64? E.g. in an IF statement.

Is there a way to check with this code if some variable value was coded in base64? E.g. in an IF statement.
jpetso commented 2019-02-10 13:38:42 -06:00 (Migrated from github.com)

(I'm going to assume that the title was meant to refer to base64 like in your leading comment.)

There currently isn't a function that specifically returns a true or false value. I've been wanting to introduce one of these along with changes that make cppcodec error handling work without requiring exceptions. Haven't gotten to that part yet (sorry).

So what you can do right now is call any variant of base64_rfc4648::decode() with a throwaway binary_result argument and catch cppcodec::parse_error. If it throws a parse error, it's doesn't conform to base64_rfc4648.

Does that work for you until I get around to implementing a more proper validity-checking function?

(I'm going to assume that the title was meant to refer to base64 like in your leading comment.) There currently isn't a function that specifically returns a `true` or `false` value. I've been wanting to introduce one of these along with changes that make cppcodec error handling work without requiring exceptions. Haven't gotten to that part yet (sorry). So what you *can* do right now is call any variant of `base64_rfc4648::decode()` with a throwaway `binary_result` argument and catch `cppcodec::parse_error`. If it throws a parse error, it's doesn't conform to `base64_rfc4648`. Does that work for you until I get around to implementing a more proper validity-checking function?
jpetso commented 2019-02-10 13:46:46 -06:00 (Migrated from github.com)

Also relevant: issue #4 (yeah, I haven't made progress on this for a while now)

Also relevant: issue #4 (yeah, I haven't made progress on this for a while now)
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-tplgy/cppcodec#66
No description provided.