mirror of
https://github.com/openssl/openssl.git
synced 2024-12-15 06:01:37 +08:00
1d39620b34
This library is meant to be small and quick. It's based on WPACKET, which was extended to support DER writing. The way it's used is a bit unusual, as it's used to write the structures backward into a given buffer. A typical quick call looks like this: /* * Fill in this structure: * * something ::= SEQUENCE { * id OBJECT IDENTIFIER, * x [0] INTEGER OPTIONAL, * y [1] BOOLEAN OPTIONAL, * n INTEGER * } */ unsigned char buf[nnnn], *p = NULL; size_t encoded_len = 0; WPACKET pkt; int ok; ok = WPACKET_init_der(&pkt, buf, sizeof(buf) && DER_w_start_sequence(&pkt, -1) && DER_w_bn(&pkt, -1, bn) && DER_w_boolean(&pkt, 1, bool) && DER_w_precompiled(&pkt, -1, OID, sizeof(OID)) && DER_w_end_sequence(&pkt, -1) && WPACKET_finish(&pkt) && WPACKET_get_total_written(&pkt, &encoded_len) && (p = WPACKET_get_curr(&pkt)) != NULL; Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/11450)
49 lines
1.4 KiB
Plaintext
49 lines
1.4 KiB
Plaintext
=pod
|
|
|
|
=head1 NAME
|
|
|
|
DER_w_precompiled
|
|
- internal DER writers for precompiled DER blobs
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
#include "internal/der.h"
|
|
|
|
int DER_w_precompiled(WPACKET *pkt, int tag,
|
|
const unsigned char *precompiled,
|
|
size_t precompiled_n);
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
There may be already existing DER blobs that can simply be copied to
|
|
the buffer held by I<pkt>. For example, precompiled values, such as
|
|
OIDs (for example, C<id-sha256>) or complete AlgorithmIdentifiers
|
|
(for example, C<sha256Identifier>). To add those as an element in a
|
|
structure being DER encoded, use DER_w_precompiled().
|
|
|
|
DER_w_precompiled() will simply take the DER encoded blob given as
|
|
I<precompiled> with length I<precompiled_n> and add it to the buffer
|
|
held by I<pkt>.
|
|
|
|
=head1 RETURN VALUES
|
|
|
|
DER_w_precompiled() returns 1 on success and 0 on failure. Failure
|
|
may mean that the buffer held by the I<pkt> is too small, but may also
|
|
mean that the values given to the functions are invalid, such as the provided
|
|
I<tag> value being too large for the implementation.
|
|
|
|
=head1 SEE ALSO
|
|
|
|
L<DERlib(7)>
|
|
|
|
=head1 COPYRIGHT
|
|
|
|
Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
|
|
|
|
Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
this file except in compliance with the License. You can obtain a copy
|
|
in the file LICENSE in the source distribution or at
|
|
L<https://www.openssl.org/source/license.html>.
|
|
|
|
=cut
|