diff options
| -rw-r--r-- | lib/util/asn1.c | 35 | ||||
| -rw-r--r-- | lib/util/asn1.h | 1 | 
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/util/asn1.c b/lib/util/asn1.c index 70c2c57450..61fb9555a7 100644 --- a/lib/util/asn1.c +++ b/lib/util/asn1.c @@ -258,6 +258,41 @@ bool ber_write_OID_String(DATA_BLOB *blob, const char *OID)  	return true;  } +/** + * Serialize partial OID string. + * Partial OIDs are in the form: + *   1:2.5.6:0x81 + *   1:2.5.6:0x8182 + */ +bool ber_write_partial_OID_String(DATA_BLOB *blob, const char *partial_oid) +{ +	TALLOC_CTX *mem_ctx = talloc_new(NULL); +	char *oid = talloc_strdup(mem_ctx, partial_oid); +	char *p; + +	/* truncate partial part so ber_write_OID_String() works */ +	p = strchr(oid, ':'); +	if (p) { +		*p = '\0'; +		p++; +	} + +	if (!ber_write_OID_String(blob, oid)) { +		talloc_free(mem_ctx); +		return false; +	} + +	/* Add partially endcoded subidentifier */ +	if (p) { +		DATA_BLOB tmp_blob = strhex_to_data_blob(mem_ctx, p); +		data_blob_append(NULL, blob, tmp_blob.data, tmp_blob.length); +	} + +	talloc_free(mem_ctx); + +	return true; +} +  /* write an object ID to a ASN1 buffer */  bool asn1_write_OID(struct asn1_data *data, const char *OID)  { diff --git a/lib/util/asn1.h b/lib/util/asn1.h index 9abae50d64..cd93195870 100644 --- a/lib/util/asn1.h +++ b/lib/util/asn1.h @@ -62,6 +62,7 @@ bool asn1_write_implicit_Integer(struct asn1_data *data, int i);  bool asn1_write_Integer(struct asn1_data *data, int i);  bool asn1_write_BitString(struct asn1_data *data, const void *p, size_t length, uint8_t padding);  bool ber_write_OID_String(DATA_BLOB *blob, const char *OID); +bool ber_write_partial_OID_String(DATA_BLOB *blob, const char *partial_oid);  bool asn1_write_OID(struct asn1_data *data, const char *OID);  bool asn1_write_OctetString(struct asn1_data *data, const void *p, size_t length);  bool asn1_write_LDAPString(struct asn1_data *data, const char *s);  | 
