NAME
Crypt::SecretBuffer::PEM::Headers - Inspect or alter arrayref of PEM headers as if it was a hashref
SYNOPSIS
my $headers= Crypt::SecretBuffer::PEM::Headers->new(
raw_kv_array => [
x => 1,
X => 2,
' X ' => 3,
],
trim_keys => 1,
caseless_keys => 1,
);
my $vals= $headers->get('x');
# [1,2,3]
$headers->set(a => 5);
my $kv= $headers->raw_kv_array;
# ['x',1,'X',2,' X ',3,a,5]
DESCRIPTION
This object provides hash-like behavior for inspecting the headers of a PEM file while maintaining the original arrayref of PEM headers found in the file. This module manages character encoding/decoding, case-insensitive comparison, whitespace trimming, and merging the values of duplicate header names into arrayrefs. The original whitespace and character encoding and header order are preserverd in case you want to make minimal changes and then re-serialize the PEM file without altering more than you intended.
CONSTRUCTORS
new
$headers= Crypt::SecretBuffer::PEM::Headers->new(%attrs);
ATTRIBUTES
raw_kv_array
This is an arrayref of [$key0, $val0, $key1, $val1, ...] which was parsed from the PEM header section, in its original order, capitalization, and byte encoding. The methods of this object modify the array.
unicode_keys
If true, assume all keys in "raw_kv_list" are encoded as UTF-8. Any that aren't will possibly trigger exceptions, or just not match any attempt to read/write them. Any new keys you add are expected to be unicode (wide characters) and will be encoded as UTF-8 automatically. If false, it uses byte matching between the string you supply, and your string must be downgradable to plain bytes.
unicode_values
If true, assume all values in "raw_kv_list" are encoded as UTF-8. Any that aren't will possibly throw exceptions.
trim_keys
If true (the default) any leading or trailing whitespace (\s in the key name will be ignored while comparing to the key name you requested. The whitespace remains in the original KV list for clean round-trips.
caseless_keys
If true, get/set/delete operations on key names will perform a case-insensitive match. The original case of the keys is preserved.
METHODS
keys
@name_list= $headers->keys;
Return the list of header names, with duplicates collapsed. The returned order is the same as they occur in the "raw_kv_array".
get_array
$array= $headers->get_array($name);
Return an arrayref of all values for matching key names. This performs a scan of raw_kv_array and collects the values of matching keys into an arrayref.
get
$val_or_array= $headers->get($name);
Return the value or arrayref of values or undef for matching keys names.
set
$headers->set($name => $value);
$headers->set($name => \@values);
Overwrite any existing values for the header $name with the supplied values. If there are multiple matches, the values other than the first will all be deleted from the array. If multiple new values are provided, they will all be inserted at the location of the first previous value, or the end of the list of there was no previous value.
append
$headers->append($name => $value);
Append one name/value pair to the end of the list.
delete
@val_list= $headers->delete($name);
Delete all headers matching $name, and return the values deleted.
VERSION
version 0.019
AUTHOR
Michael Conrad <mike@nrdvana.net>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Michael Conrad.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.