Result of wrapping a session key for ECDH key
This commit is contained in:
parent
01be192a35
commit
d8b1e3359a
|
@ -77,6 +77,12 @@ export { default as S2K } from './type/s2k';
|
|||
*/
|
||||
export { default as Keyid } from './type/keyid';
|
||||
|
||||
/**
|
||||
* @see module:type/ecdh_symkey
|
||||
* @name module:openpgp.EcdhSymmetricKey
|
||||
*/
|
||||
export { default as EcdhSymmetricKey } from './type/ecdh_symkey';
|
||||
|
||||
/**
|
||||
* @see module:type/oid
|
||||
* @name module:openpgp.Oid
|
||||
|
|
71
src/type/ecdh_symkey.js
Normal file
71
src/type/ecdh_symkey.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
// OpenPGP.js - An OpenPGP implementation in javascript
|
||||
// Copyright (C) 2015-2016 Decentral
|
||||
//
|
||||
// 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
|
||||
|
||||
/**
|
||||
* Encoded symmetric key for ECDH<br/>
|
||||
* <br/>
|
||||
* @requires util
|
||||
* @module type/ecdh_symkey
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import util from '../util.js';
|
||||
|
||||
module.exports = EcdhSymmetricKey;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function EcdhSymmetricKey(data) {
|
||||
if (typeof data === 'undefined') {
|
||||
data = new Uint8Array([]);
|
||||
} else if (typeof data === 'string') {
|
||||
data = util.str2Uint8Array(data);
|
||||
} else {
|
||||
data = new Uint8Array(data);
|
||||
}
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an EcdhSymmetricKey from an Uint8Array
|
||||
* @param {Uint8Array} input Where to read the encoded symmetric key from
|
||||
* @return {Number} Number of read bytes
|
||||
*/
|
||||
EcdhSymmetricKey.prototype.read = function (input) {
|
||||
if (input.length >= 1)
|
||||
{
|
||||
var length = input[0];
|
||||
if (input.length >= 1+length)
|
||||
{
|
||||
this.data = input.subarray(1, 1+length);
|
||||
return 1+this.data.length;
|
||||
}
|
||||
}
|
||||
throw new Error('Invalid symmetric key');
|
||||
};
|
||||
|
||||
/**
|
||||
* Write an EcdhSymmetricKey as an Uint8Array
|
||||
* @return {Uint8Array} An array containing the value
|
||||
*/
|
||||
EcdhSymmetricKey.prototype.write = function () {
|
||||
return util.concatUint8Array([
|
||||
new Uint8Array([this.data.length]),
|
||||
this.data]);
|
||||
};
|
Loading…
Reference in New Issue
Block a user