-/* $OpenBSD: ber.c,v 1.20 2021/01/28 19:56:33 martijn Exp $ */
+/* $OpenBSD: ber.c,v 1.21 2021/02/22 17:15:02 martijn Exp $ */
/*
* Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
if (elm->be_encoding != BER_TYPE_INTEGER)
return -1;
- *n = elm->be_numeric;
+ if (n != NULL)
+ *n = elm->be_numeric;
return 0;
}
if (elm->be_encoding != BER_TYPE_ENUMERATED)
return -1;
- *n = elm->be_numeric;
+ if (n != NULL)
+ *n = elm->be_numeric;
return 0;
}
if (elm->be_encoding != BER_TYPE_BOOLEAN)
return -1;
- *b = !(elm->be_numeric == 0);
+ if (b != NULL)
+ *b = !(elm->be_numeric == 0);
return 0;
}
return -1;
#endif
- *s = elm->be_val;
+ if (s != NULL)
+ *s = elm->be_val;
return 0;
}
if (elm->be_encoding != BER_TYPE_OCTETSTRING)
return -1;
- *p = elm->be_val;
- *len = elm->be_len;
+ if (len != NULL)
+ *len = elm->be_len;
+ if (p != NULL) {
+ if (len != NULL)
+ *p = elm->be_val;
+ else
+ *p = NULL;
+ }
return 0;
}
if (elm->be_encoding != BER_TYPE_OCTETSTRING)
return -1;
- s->ostr_val = elm->be_val;
- s->ostr_len = elm->be_len;
+ if (s != NULL) {
+ s->ostr_val = elm->be_val;
+ s->ostr_len = elm->be_len;
+ }
return 0;
}
if (elm->be_encoding != BER_TYPE_BITSTRING)
return -1;
- *v = elm->be_val;
- *len = elm->be_len;
+ if (len != NULL)
+ *len = elm->be_len;
+ if (v != NULL) {
+ if (len != NULL)
+ *v = elm->be_val;
+ else
+ *v = NULL;
+ }
return 0;
}
if (elm->be_encoding != BER_TYPE_OBJECT)
return (-1);
+ if (o == NULL)
+ return 0;
+
buf = elm->be_val;
len = elm->be_len;
d = va_arg(ap, int *);
if (ober_get_integer(ber, &l) == -1)
goto fail;
- *d = l;
+ if (d != NULL)
+ *d = l;
ret++;
break;
case 'e':
case 't':
d = va_arg(ap, int *);
t = va_arg(ap, unsigned int *);
- *d = ber->be_class;
- *t = ber->be_type;
+ if (d != NULL)
+ *d = ber->be_class;
+ if (t != NULL)
+ *t = ber->be_type;
ret++;
continue;
case 'x':
-.\" $OpenBSD: ober_get_string.3,v 1.3 2021/01/28 19:56:33 martijn Exp $
+.\" $OpenBSD: ober_get_string.3,v 1.4 2021/02/22 17:15:02 martijn Exp $
.\"
.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
.\"
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: January 28 2021 $
+.Dd $Mdocdate: February 22 2021 $
.Dt OBER_GET_STRING 3
.Os
.Sh NAME
Functions which take two arguments save the value contained in the
.Fa root
element into the storage location pointed to by the second argument.
+If the storage location is
+.Dv NULL
+then only a type check is performed.
Additionally,
.Fn ober_get_nstring
and
.Fn ober_get_bitstring
save the number of bytes contained in the string into
.Pf * Fa size .
+If
+.Fa buf
+is
+.Dv NULL
+and size is not
+.Dv NULL ,
+size is set.
+.Fa size
+must not be
+.Dv NULL
+to return a valid
+.Fa buf .
.Pp
.Fn ober_scanf_elements
retrieves the values from zero or more elements starting at