static int test_string_tbl(void) { const ASN1_STRING_TABLE *tmp = NULL; int nid = 12345678, nid2 = 87654321, rv = 0, ret = 0; tmp = ASN1_STRING_TABLE_get(nid); if (!TEST_ptr_null(tmp)) { TEST_info("asn1 string table: ASN1_STRING_TABLE_get non-exist nid"); goto out; } ret = ASN1_STRING_TABLE_add(nid, -1, -1, MBSTRING_ASC, 0); if (!TEST_true(ret)) { TEST_info("asn1 string table: add NID(%d) failed", nid); goto out; } ret = ASN1_STRING_TABLE_add(nid2, -1, -1, MBSTRING_ASC, 0); if (!TEST_true(ret)) { TEST_info("asn1 string table: add NID(%d) failed", nid2); goto out; } tmp = ASN1_STRING_TABLE_get(nid); if (!TEST_ptr(tmp)) { TEST_info("asn1 string table: get NID(%d) failed", nid); goto out; } tmp = ASN1_STRING_TABLE_get(nid2); if (!TEST_ptr(tmp)) { TEST_info("asn1 string table: get NID(%d) failed", nid2); goto out; } ASN1_STRING_TABLE_cleanup(); /* check if all newly added NIDs are cleaned up */ tmp = ASN1_STRING_TABLE_get(nid); if (!TEST_ptr_null(tmp)) { TEST_info("asn1 string table: get NID(%d) failed", nid); goto out; } tmp = ASN1_STRING_TABLE_get(nid2); if (!TEST_ptr_null(tmp)) { TEST_info("asn1 string table: get NID(%d) failed", nid2); goto out; } rv = 1; out: return rv; }
int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize, unsigned long mask, unsigned long flags) { ASN1_STRING_TABLE *tmp; char new_nid = 0; flags &= ~STABLE_FLAGS_MALLOC; if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); if(!stable) { ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); return 0; } if(!(tmp = ASN1_STRING_TABLE_get(nid))) { tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE)); if(!tmp) { ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); return 0; } tmp->flags = flags | STABLE_FLAGS_MALLOC; tmp->nid = nid; new_nid = 1; } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags; if(minsize != -1) tmp->minsize = minsize; if(maxsize != -1) tmp->maxsize = maxsize; tmp->mask = mask; if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp); return 1; }
ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, int inlen, int inform, int nid) { ASN1_STRING_TABLE *tbl; ASN1_STRING *str = NULL; unsigned long mask; int ret; if (!out) out = &str; tbl = ASN1_STRING_TABLE_get(nid); if (tbl) { mask = tbl->mask; if (!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask; ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask, tbl->minsize, tbl->maxsize); } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask); if (ret <= 0) return NULL; return *out; }
static ASN1_STRING_TABLE *stable_get(int nid) { ASN1_STRING_TABLE *tmp, *rv; /* Always need a string table so allocate one if NULL */ if (stable == NULL) { stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); if (stable == NULL) return NULL; } tmp = ASN1_STRING_TABLE_get(nid); if (tmp && tmp->flags & STABLE_FLAGS_MALLOC) return tmp; rv = OPENSSL_zalloc(sizeof(*rv)); if (rv == NULL) return NULL; if (!sk_ASN1_STRING_TABLE_push(stable, rv)) { OPENSSL_free(rv); return NULL; } if (tmp) { rv->nid = tmp->nid; rv->minsize = tmp->minsize; rv->maxsize = tmp->maxsize; rv->mask = tmp->mask; rv->flags = tmp->flags | STABLE_FLAGS_MALLOC; } else { rv->nid = nid; rv->minsize = -1; rv->maxsize = -1; rv->flags = STABLE_FLAGS_MALLOC; } return rv; }
/* returns an encoded ASN1 string from QString for a special nid*/ ASN1_STRING *QStringToAsn1(const QString s, int nid) { QByteArray ba = s.toUtf8(); const unsigned char *utf8 = (const unsigned char *)ba.constData(); unsigned long global_mask = ASN1_STRING_get_default_mask(); unsigned long mask = DIRSTRING_TYPE & global_mask; ASN1_STRING *out = NULL; ASN1_STRING_TABLE *tbl; tbl = ASN1_STRING_TABLE_get(nid); if (tbl) { mask = tbl->mask; if (!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask; } ASN1_mbstring_copy(&out, utf8, -1, MBSTRING_UTF8, mask); openssl_error(QString("'%1' (%2)").arg(s).arg(OBJ_nid2ln(nid))); return out; }
void NewX509::setupLineEditByNid(int nid, QLineEdit *l) { ASN1_STRING_TABLE *tab = ASN1_STRING_TABLE_get(nid); QValidator *validator = NULL; QStringList info; info << QString("[%1]").arg(OBJ_nid2sn(nid)); if (tab) { if (tab->minsize > 1) info << tr("minimum size: %1").arg(tab->minsize); if (tab->maxsize != -1) info << tr("maximum size: %1").arg(tab->maxsize); if (tab->mask == B_ASN1_PRINTABLESTRING) { info << tr("only a-z A-Z 0-9 '()+,-./:=?"); QRegExp rx("[a-zA-Z0-9'()+,-./:=?]+"); validator = new QRegExpValidator(rx, this); } else if (tab->mask == B_ASN1_IA5STRING) { info << tr("only 7-bit clean characters"); } } l->setToolTip(info.join(" ")); l->setValidator(validator); }