[Swan-dev] lib/libswan/asn1.c: eliminate loop from is_printablestring()

D. Hugh Redelmeier hugh at mimosa.com
Sun Nov 4 04:02:01 UTC 2018


| From: Andrew Cagney <andrew.cagney at gmail.com>
| > Author: D. Hugh Redelmeier <hugh at mimosa.com>

| >     lib/libswan/asn1.c: eliminate loop from is_printablestring()

| I have to ask.  Could isprint() be used, or is there ASN.1 magic
| involved in the decision of what is printable?

The definition of ASN1_PRINTABLESTRING specifies exactly the set of
characters listed (unless there was a mistake).

Notice that '*' is not one of those characters.  A number of systems
have bugs where they encode wildcards as PRINTABLESTRINGs.  I think
that we'll accept that but won't generate it.

| (yea, there isn't shunk_strspn())

Some parts of x509.c should use shunks.  Not all.

strspn could be implemented fairly efficiently, at least if strings
are long enough to amortize the cost of building a table subscripted
by the character code (like isprint() before wide characters).

We could build our own table, once, at compile time.  We'd need to
re-introduce the loop to use it, but that's OK.  The loop of strchr's
was a bit rude (but probably didn't get used enough to matter).


More information about the Swan-dev mailing list