blob: 29a3add0b095ac224451c1865cb8b2a821fdd16c [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 Publisher and PublisherType Objects
5 */
6
7
8var PublisherType = function PublisherType(_tag){
9 this.KEY =(CCNProtocolDTags.PublisherPublicKeyDigest);
10 this.CERTIFICATE= (CCNProtocolDTags.PublisherCertificateDigest);
11 this.ISSUER_KEY= (CCNProtocolDTags.PublisherIssuerKeyDigest);
12 this.ISSUER_CERTIFICATE =(CCNProtocolDTags.PublisherIssuerCertificateDigest);
13
14 this.Tag = _tag;
15};
16
17var isTypeTagVal = function(tagVal) {
18 if ((tagVal == CCNProtocolDTags.PublisherPublicKeyDigest) ||
19 (tagVal == CCNProtocolDTags.PublisherCertificateDigest) ||
20 (tagVal == CCNProtocolDTags.PublisherIssuerKeyDigest) ||
21 (tagVal == CCNProtocolDTags.PublisherIssuerCertificateDigest)) {
22 return true;
23 }
24 return false;
25};
26
27
28
29
30var PublisherID = function PublisherID() {
31
32 this.PUBLISHER_ID_DIGEST_ALGORITHM = "SHA-256";
33 this.PUBLISHER_ID_LEN = 256/8;
34
35 //TODO, implement publisherID creation and key creation
36
37 //TODO implement generatePublicKeyDigest
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070038 this.publisherID =null;//= generatePublicKeyDigest(key);//ByteArray
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070039
40 //TODO implement generate key
41 //CryptoUtil.generateKeyID(PUBLISHER_ID_DIGEST_ALGORITHM, key);
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070042 this.publisherType = null;//isIssuer ? PublisherType.ISSUER_KEY : PublisherType.KEY;//publisher Type
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070043
44};
45
46
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070047PublisherID.prototype.from_ccnb = function(decoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070048
49 // We have a choice here of one of 4 binary element types.
50 var nextTag = decoder.peekStartElementAsLong();
51
52 if (null == nextTag) {
Jeff Thompson34a2ec02012-09-29 21:47:05 -070053 throw new Error("Cannot parse publisher ID.");
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070054 }
55
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070056 this.publisherType = new PublisherType(nextTag);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070057
58 if (!isTypeTagVal(nextTag)) {
Jeff Thompson34a2ec02012-09-29 21:47:05 -070059 throw new Error("Invalid publisher ID, got unexpected type: " + nextTag);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070060 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070061 this.publisherID = decoder.readBinaryElement(nextTag);
62 if (null == this.publisherID) {
Jeff Thompsoncab74c32012-10-21 13:27:28 -070063 throw new ContentDecodingException(new Error("Cannot parse publisher ID of type : " + nextTag + "."));
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070064 }
65};
66
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070067PublisherID.prototype.to_ccnb = function(encoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070068 if (!this.validate()) {
Jeff Thompson34a2ec02012-09-29 21:47:05 -070069 throw new Error("Cannot encode " + this.getClass().getName() + ": field values missing.");
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070070 }
71
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070072 encoder.writeElement(this.getElementLabel(), this.publisherID);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070073};
74
Jeff Thompson86aea882012-09-29 17:32:48 -070075PublisherID.peek = function(/* XMLDecoder */ decoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070076
77 //Long
78 nextTag = decoder.peekStartElementAsLong();
79
80 if (null == nextTag) {
81 // on end element
82 return false;
83 }
84 return (isTypeTagVal(nextTag));
85 };
86
87PublisherID.prototype.getElementLabel = function() {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070088 return this.publisherType.Tag;
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070089};
90
91PublisherID.prototype.validate = function(){
92 return ((null != id() && (null != type())));
93};
94
95
96