blob: b85e26b065781f9b109364c4bd3abf9ed7ef2a01 [file] [log] [blame]
Meki Cherkaouif441d3a2012-04-22 15:17:52 -07001/*
2 * @author: ucla-cs
Jeff Thompson745026e2012-10-13 12:49:20 -07003 * See COPYING for copyright and distribution information.
Meki Cherkaouif441d3a2012-04-22 15:17:52 -07004 * This class represents PublisherPublicKeyDigest Objects
5 */
6var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(_pkd){
7
Meki Cherkaoui8f173612012-06-06 01:05:40 -07008 //this.PUBLISHER_ID_LEN = 256/8;
9 this.PUBLISHER_ID_LEN = 512/8;
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070010
Meki Cherkaoui8f173612012-06-06 01:05:40 -070011
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070012 this.publisherPublicKeyDigest = _pkd;
13 //if( typeof _pkd == "object") this.publisherPublicKeyDigest = _pkd; // Byte Array
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070014 //else if( typeof _pkd == "PublicKey") ;//TODO...
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070015
16};
17
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070018PublisherPublicKeyDigest.prototype.from_ccnb = function( decoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070019
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070020 this.publisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel());
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070021
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070022 if(LOG>4)console.log('Publisher public key digest is ' + this.publisherPublicKeyDigest);
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070023
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070024 if (null == this.publisherPublicKeyDigest) {
Jeff Thompson34a2ec02012-09-29 21:47:05 -070025 throw new Error("Cannot parse publisher key digest.");
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070026 }
27
28 //TODO check if the length of the PublisherPublicKeyDigest is correct ( Security reason)
29
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070030 if (this.publisherPublicKeyDigest.length != this.PUBLISHER_ID_LEN) {
Jeff Thompsoncf187ff2012-10-21 16:18:55 -070031 if (LOG > 0)
32 console.log('LENGTH OF PUBLISHER ID IS WRONG! Expected ' + this.PUBLISHER_ID_LEN + ", got " + this.publisherPublicKeyDigest.length);
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070033
Jeff Thompsoncf187ff2012-10-21 16:18:55 -070034 //this.publisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest;
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070035 }
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070036 };
37
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070038PublisherPublicKeyDigest.prototype.to_ccnb= function( encoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070039 //TODO Check that the ByteArray for the key is present
Meki Cherkaoui8f173612012-06-06 01:05:40 -070040 if (!this.validate()) {
Jeff Thompson34a2ec02012-09-29 21:47:05 -070041 throw new Error("Cannot encode : field values missing.");
Meki Cherkaoui8f173612012-06-06 01:05:40 -070042 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070043 if(LOG>3) console.log('PUBLISHER KEY DIGEST IS'+this.publisherPublicKeyDigest);
44 encoder.writeElement(this.getElementLabel(), this.publisherPublicKeyDigest);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070045};
46
47PublisherPublicKeyDigest.prototype.getElementLabel = function() { return CCNProtocolDTags.PublisherPublicKeyDigest; };
48
49PublisherPublicKeyDigest.prototype.validate =function() {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070050 return (null != this.publisherPublicKeyDigest);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070051};