Files
openpgpjs/src/packet/padding.js
larabr 2a8969b437 Internal: improve tree-shaking for crypto modules
Every submodule under the 'crypto' directory was exported-imported
even if a handful of functions where actually needed.
We now only export entire modules behind default exports if it makes
sense for readability and if the different submodules would be
imported together anyway (e.g. `cipherMode` exports are all needed
by the SEIPD class).

We've also dropped exports that are not used outside of the crypto modules,
e.g. pkcs5 helpers.
2024-11-22 14:32:39 +01:00

64 lines
1.9 KiB
JavaScript

// OpenPGP.js - An OpenPGP implementation in javascript
// Copyright (C) 2022 Proton AG
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3.0 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import { getRandomBytes } from '../crypto';
import enums from '../enums';
/**
* Implementation of the Padding Packet
*
* {@link https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-crypto-refresh#name-padding-packet-tag-21}:
* Padding Packet
*/
class PaddingPacket {
static get tag() {
return enums.packet.padding;
}
constructor() {
this.padding = null;
}
/**
* Read a padding packet
* @param {Uint8Array | ReadableStream<Uint8Array>} bytes
*/
read(bytes) { // eslint-disable-line @typescript-eslint/no-unused-vars
// Padding packets are ignored, so this function is never called.
}
/**
* Write the padding packet
* @returns {Uint8Array} The padding packet.
*/
write() {
return this.padding;
}
/**
* Create random padding.
* @param {Number} length - The length of padding to be generated.
* @throws {Error} if padding generation was not successful
* @async
*/
async createPadding(length) {
this.padding = await getRandomBytes(length);
}
}
export default PaddingPacket;