From 329def30c5f62f362150abdc8672426cd5db106c Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Fri, 6 Sep 2013 16:34:38 +0200
Subject: [PATCH] Added asn1_write_bool()
---
include/polarssl/asn1write.h | 12 ++++++++++++
library/asn1write.c | 17 +++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/include/polarssl/asn1write.h b/include/polarssl/asn1write.h
index 4659b24c1..808bf3abe 100644
--- a/include/polarssl/asn1write.h
+++ b/include/polarssl/asn1write.h
@@ -124,6 +124,18 @@ int asn1_write_oid( unsigned char **p, unsigned char *start, const char *oid );
int asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start,
const char *oid );
+/**
+ * \brief Write a boolean tag (ASN1_BOOLEAN) and value in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param boolean 0 or 1
+ *
+ * \return the length written or a negative error code
+ */
+int asn1_write_bool( unsigned char **p, unsigned char *start, int boolean );
+
/**
* \brief Write an int tag (ASN1_INTEGER) and value in ASN.1 format
* Note: function works backwards in data buffer
diff --git a/library/asn1write.c b/library/asn1write.c
index 463c730fb..893841f80 100644
--- a/library/asn1write.c
+++ b/library/asn1write.c
@@ -173,6 +173,23 @@ int asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start,
return( len );
}
+int asn1_write_bool( unsigned char **p, unsigned char *start, int boolean )
+{
+ int ret;
+ size_t len = 0;
+
+ if( *p - start < 1 )
+ return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
+
+ *--(*p) = (boolean) ? 1 : 0;
+ len++;
+
+ ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
+ ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_BOOLEAN ) );
+
+ return( len );
+}
+
int asn1_write_int( unsigned char **p, unsigned char *start, int val )
{
int ret;