
work correctly with utf8 strings. Fixeda visibility issue with the testing suite and added relevant unit tests.
205 lines
13 KiB
HTML
205 lines
13 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>JSDoc: Source: packet/openpgp.packet.userattribute.js</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"> </script>
|
|
<script src="scripts/prettify/lang-css.js"> </script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">Source: packet/openpgp.packet.userattribute.js</h1>
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source"><code>// GPG4Browsers - An OpenPGP implementation in javascript
|
|
// Copyright (C) 2011 Recurity Labs GmbH
|
|
//
|
|
// 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 2.1 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
|
|
|
|
/**
|
|
* @class
|
|
* @classdesc Implementation of the User Attribute Packet (Tag 17)
|
|
* The User Attribute packet is a variation of the User ID packet. It
|
|
* is capable of storing more types of data than the User ID packet,
|
|
* which is limited to text. Like the User ID packet, a User Attribute
|
|
* packet may be certified by the key owner ("self-signed") or any other
|
|
* key owner who cares to certify it. Except as noted, a User Attribute
|
|
* packet may be used anywhere that a User ID packet may be used.
|
|
*
|
|
* While User Attribute packets are not a required part of the OpenPGP
|
|
* standard, implementations SHOULD provide at least enough
|
|
* compatibility to properly handle a certification signature on the
|
|
* User Attribute packet. A simple way to do this is by treating the
|
|
* User Attribute packet as a User ID packet with opaque contents, but
|
|
* an implementation may use any method desired.
|
|
*/
|
|
function openpgp_packet_userattribute() {
|
|
this.tagType = 17;
|
|
this.certificationSignatures = new Array();
|
|
this.certificationRevocationSignatures = new Array();
|
|
this.revocationSignatures = new Array();
|
|
this.parentNode = null;
|
|
|
|
/**
|
|
* parsing function for a user attribute packet (tag 17).
|
|
* @param {String} input payload of a tag 17 packet
|
|
* @param {Integer} position position to start reading from the input string
|
|
* @param {Integer} len length of the packet or the remaining length of input at position
|
|
* @return {openpgp_packet_encrypteddata} object representation
|
|
*/
|
|
function read_packet (input, position, len) {
|
|
var total_len = 0;
|
|
this.packetLength = len;
|
|
this.userattributes = new Array();
|
|
var count = 0;
|
|
var mypos = position;
|
|
while (len != total_len) {
|
|
var current_len = 0;
|
|
// 4.2.2.1. One-Octet Lengths
|
|
if (input[mypos].charCodeAt() < 192) {
|
|
packet_length = input[mypos++].charCodeAt();
|
|
current_len = 1;
|
|
// 4.2.2.2. Two-Octet Lengths
|
|
} else if (input[mypos].charCodeAt() >= 192 && input[mypos].charCodeAt() < 224) {
|
|
packet_length = ((input[mypos++].charCodeAt() - 192) << 8)
|
|
+ (input[mypos++].charCodeAt()) + 192;
|
|
current_len = 2;
|
|
// 4.2.2.4. Partial Body Lengths
|
|
} else if (input[mypos].charCodeAt() > 223 && input[mypos].charCodeAt() < 255) {
|
|
packet_length = 1 << (input[mypos++].charCodeAt() & 0x1F);
|
|
current_len = 1;
|
|
// 4.2.2.3. Five-Octet Lengths
|
|
} else {
|
|
current_len = 5;
|
|
mypos++;
|
|
packet_length = (input[mypos++].charCodeAt() << 24) | (input[mypos++].charCodeAt() << 16)
|
|
| (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt();
|
|
}
|
|
|
|
var subpackettype = input[mypos++].charCodeAt();
|
|
packet_length--;
|
|
current_len++;
|
|
this.userattributes[count] = new Array();
|
|
this.userattributes[count] = input.substring(mypos, mypos + packet_length);
|
|
mypos += packet_length;
|
|
total_len += current_len+packet_length;
|
|
}
|
|
this.packetLength = mypos - position;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* generates debug output (pretty print)
|
|
* @return {String} String which gives some information about the user attribute packet
|
|
*/
|
|
function toString() {
|
|
var result = '5.12. User Attribute Packet (Tag 17)\n'+
|
|
' AttributePackets: (count = '+this.userattributes.length+')\n';
|
|
for (var i = 0; i < this.userattributes.length; i++) {
|
|
result += ' ('+this.userattributes[i].length+') bytes: ['+util.hexidump(this.userattributes[i])+']\n';
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Continue parsing packets belonging to the user attribute packet such as signatures
|
|
* @param {Object} parent_node the parent object
|
|
* @param {String} input input string to read the packet(s) from
|
|
* @param {Integer} position start position for the parser
|
|
* @param {Integer} len length of the packet(s) or remaining length of input
|
|
* @return {Integer} length of nodes read
|
|
*/
|
|
function read_nodes(parent_node, input, position, len) {
|
|
|
|
this.parentNode = parent_node;
|
|
var exit = false;
|
|
var pos = position;
|
|
var l = len;
|
|
while (input.length != pos) {
|
|
var result = openpgp_packet.read_packet(input, pos, l);
|
|
if (result == null) {
|
|
util.print_error("openpgp.packet.userattribute.js\n"+'[user_attr] parsing ends here @:' + pos + " l:" + l);
|
|
break;
|
|
} else {
|
|
switch (result.tagType) {
|
|
case 2: // Signature Packet
|
|
if (result.signatureType > 15
|
|
&& result.signatureType < 20) // certification
|
|
// //
|
|
// signature
|
|
this.certificationSignatures[this.certificationSignatures.length] = result;
|
|
else if (result.signatureType == 32) // certification revocation signature
|
|
this.certificationRevocationSignatures[this.certificationRevocationSignatures.length] = result;
|
|
pos += result.packetLength + result.headerLength;
|
|
l = len - (pos - position);
|
|
break;
|
|
default:
|
|
this.data = input;
|
|
this.position = position - parent_node.packetLength;
|
|
this.len = pos - position;
|
|
return this.len;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
this.data = input;
|
|
this.position = position - parent_node.packetLength;
|
|
this.len = pos - position;
|
|
return this.len;
|
|
|
|
}
|
|
|
|
this.read_packet = read_packet;
|
|
this.read_nodes = read_nodes;
|
|
this.toString = toString;
|
|
|
|
};
|
|
</code></pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<nav>
|
|
<h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="_openpgp_packet.html">_openpgp_packet</a></li><li><a href="JXG.Util.html">Util</a></li><li><a href="openpgp.html">openpgp</a></li><li><a href="openpgp_config.html">openpgp_config</a></li><li><a href="openpgp_keyring.html">openpgp_keyring</a></li><li><a href="openpgp_msg_message.html">openpgp_msg_message</a></li><li><a href="openpgp_msg_privatekey.html">openpgp_msg_privatekey</a></li><li><a href="openpgp_msg_publickey.html">openpgp_msg_publickey</a></li><li><a href="openpgp_packet_compressed.html">openpgp_packet_compressed</a></li><li><a href="openpgp_packet_encrypteddata.html">openpgp_packet_encrypteddata</a></li><li><a href="openpgp_packet_encryptedintegrityprotecteddata.html">openpgp_packet_encryptedintegrityprotecteddata</a></li><li><a href="openpgp_packet_encryptedsessionkey.html">openpgp_packet_encryptedsessionkey</a></li><li><a href="openpgp_packet_keymaterial.html">openpgp_packet_keymaterial</a></li><li><a href="openpgp_packet_literaldata.html">openpgp_packet_literaldata</a></li><li><a href="openpgp_packet_marker.html">openpgp_packet_marker</a></li><li><a href="openpgp_packet_modificationdetectioncode.html">openpgp_packet_modificationdetectioncode</a></li><li><a href="openpgp_packet_onepasssignature.html">openpgp_packet_onepasssignature</a></li><li><a href="openpgp_packet_signature.html">openpgp_packet_signature</a></li><li><a href="openpgp_packet_userattribute.html">openpgp_packet_userattribute</a></li><li><a href="openpgp_packet_userid.html">openpgp_packet_userid</a></li><li><a href="openpgp_type_keyid.html">openpgp_type_keyid</a></li><li><a href="openpgp_type_mpi.html">openpgp_type_mpi</a></li><li><a href="openpgp_type_s2k.html">openpgp_type_s2k</a></li></ul><h3>Global</h3><ul><li><a href="global.html#bin2str">bin2str</a></li><li><a href="global.html#calc_checksum">calc_checksum</a></li><li><a href="global.html#crc_table">crc_table</a></li><li><a href="global.html#decode_utf8">decode_utf8</a></li><li><a href="global.html#encode_utf8">encode_utf8</a></li><li><a href="global.html#get_hashAlgorithmString">get_hashAlgorithmString</a></li><li><a href="global.html#getCheckSum">getCheckSum</a></li><li><a href="global.html#getPGPMessageType">getPGPMessageType</a></li><li><a href="global.html#hash_headers">hash_headers</a></li><li><a href="global.html#hex2bin">hex2bin</a></li><li><a href="global.html#hexidump">hexidump</a></li><li><a href="global.html#hexstrdump">hexstrdump</a></li><li><a href="global.html#MD5">MD5</a></li><li><a href="global.html#openpgp_cfb_decrypt">openpgp_cfb_decrypt</a></li><li><a href="global.html#openpgp_cfb_encrypt">openpgp_cfb_encrypt</a></li><li><a href="global.html#openpgp_cfb_mdc">openpgp_cfb_mdc</a></li><li><a href="global.html#openpgp_crypto_asymetricDecrypt">openpgp_crypto_asymetricDecrypt</a></li><li><a href="global.html#openpgp_crypto_asymetricEncrypt">openpgp_crypto_asymetricEncrypt</a></li><li><a href="global.html#openpgp_crypto_generateKeyPair">openpgp_crypto_generateKeyPair</a></li><li><a href="global.html#openpgp_crypto_generateSessionKey">openpgp_crypto_generateSessionKey</a></li><li><a href="global.html#openpgp_crypto_getHashByteLength">openpgp_crypto_getHashByteLength</a></li><li><a href="global.html#openpgp_crypto_getPrefixRandom">openpgp_crypto_getPrefixRandom</a></li><li><a href="global.html#openpgp_crypto_getPseudoRandom">openpgp_crypto_getPseudoRandom</a></li><li><a href="global.html#openpgp_crypto_getRandomBigInteger">openpgp_crypto_getRandomBigInteger</a></li><li><a href="global.html#openpgp_crypto_getRandomBytes">openpgp_crypto_getRandomBytes</a></li><li><a href="global.html#openpgp_crypto_getSecureRandom">openpgp_crypto_getSecureRandom</a></li><li><a href="global.html#openpgp_crypto_hashData">openpgp_crypto_hashData</a></li><li><a href="global.html#openpgp_crypto_MDCSystemBytes">openpgp_crypto_MDCSystemBytes</a></li><li><a href="global.html#openpgp_crypto_signData">openpgp_crypto_signData</a></li><li><a href="global.html#openpgp_crypto_symmetricDecrypt">openpgp_crypto_symmetricDecrypt</a></li><li><a href="global.html#openpgp_crypto_symmetricEncrypt">openpgp_crypto_symmetricEncrypt</a></li><li><a href="global.html#openpgp_crypto_verifySignature">openpgp_crypto_verifySignature</a></li><li><a href="global.html#openpgp_encoding_armor">openpgp_encoding_armor</a></li><li><a href="global.html#openpgp_encoding_armor_addheader">openpgp_encoding_armor_addheader</a></li><li><a href="global.html#openpgp_encoding_base64_decode">openpgp_encoding_base64_decode</a></li><li><a href="global.html#openpgp_encoding_base64_encode">openpgp_encoding_base64_encode</a></li><li><a href="global.html#openpgp_encoding_deArmor">openpgp_encoding_deArmor</a></li><li><a href="global.html#openpgp_encoding_eme_pkcs1_decode">openpgp_encoding_eme_pkcs1_decode</a></li><li><a href="global.html#openpgp_encoding_eme_pkcs1_encode">openpgp_encoding_eme_pkcs1_encode</a></li><li><a href="global.html#openpgp_encoding_emsa_pkcs1_decode">openpgp_encoding_emsa_pkcs1_decode</a></li><li><a href="global.html#openpgp_encoding_emsa_pkcs1_encode">openpgp_encoding_emsa_pkcs1_encode</a></li><li><a href="global.html#openpgp_encoding_html_encode">openpgp_encoding_html_encode</a></li><li><a href="global.html#print_debug">print_debug</a></li><li><a href="global.html#print_debug_hexstr_dump">print_debug_hexstr_dump</a></li><li><a href="global.html#print_error">print_error</a></li><li><a href="global.html#print_info">print_info</a></li><li><a href="global.html#shiftRight">shiftRight</a></li><li><a href="global.html#str2bin">str2bin</a></li><li><a href="global.html#str2Uint8Array">str2Uint8Array</a></li><li><a href="global.html#Uint8Array2str">Uint8Array2str</a></li><li><a href="global.html#util">util</a></li><li><a href="global.html#verifyCheckSum">verifyCheckSum</a></li></ul>
|
|
</nav>
|
|
|
|
<br clear="both">
|
|
|
|
<footer>
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a> on Tue Apr 16 2013 10:42:40 GMT+0200 (CEST)
|
|
</footer>
|
|
|
|
<script> prettyPrint(); </script>
|
|
</body>
|
|
</html>
|