blob: 92dec39cc9d549e0e91a42371a8aecfb20fad3f6 [file] [log] [blame]
Meki Cherkaouif441d3a2012-04-22 15:17:52 -07001/*
2 * @author: ucla-cs
3 * This class represents PublisherPublicKeyDigest Objects
4 */
5var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(_pkd){
6
7 if( typeof _pkd == "ByteArray") this.PublisherPublicKeyDigest = _pkd; // Byte Array
8 else if( typeof _pkd == "PublicKey") ;//TODO...
9
10};
11
12PublisherPublicKeyDigest.prototype.decode = function( decoder) {
13
14 this.PublisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel());
15 if (null == this.PublisherPublicKeyDigest) {
16 throw new Exception("Cannot parse publisher key digest.");
17 }
18
19 //TODO check if the length of the PublisherPublicKeyDigest is correct ( Security reason)
20
21 /*if (this.PublisherPublicKeyDigest.length != PublisherID.PUBLISHER_ID_LEN) {
22 console.log('SHOULD NOT GO HERE !!!!!!!!!!!!!!!!!!');
23 this.PublisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest;
24 }*/
25 };
26
27PublisherPublicKeyDigest.prototype.encode= function( encoder) {
28 //TODO Check that the ByteArray for the key is present
29 /*if (!this.validate()) {
30 throw new Exception("Cannot encode : field values missing.");
31 }*/
32
33 if (this.PublisherKeyDigest!=null)this.encoder.writeElement(this.getElementLabel(), this.PublisherKeyDigest);
34};
35
36PublisherPublicKeyDigest.prototype.getElementLabel = function() { return CCNProtocolDTags.PublisherPublicKeyDigest; };
37
38PublisherPublicKeyDigest.prototype.validate =function() {
39 return (null != this.PublisherKeyDigest);
40};