blob: 1c984354e5b10f1bba1aac4d772bd95daf50eeee [file] [log] [blame]
Meki Cherkaouif441d3a2012-04-22 15:17:52 -07001/*
2 * @author: ucla-cs
3 * This class represents Publisher and PublisherType Objects
4 */
5
6
7var PublisherType = function PublisherType(_tag){
8 this.KEY =(CCNProtocolDTags.PublisherPublicKeyDigest);
9 this.CERTIFICATE= (CCNProtocolDTags.PublisherCertificateDigest);
10 this.ISSUER_KEY= (CCNProtocolDTags.PublisherIssuerKeyDigest);
11 this.ISSUER_CERTIFICATE =(CCNProtocolDTags.PublisherIssuerCertificateDigest);
12
13 this.Tag = _tag;
14};
15
16var isTypeTagVal = function(tagVal) {
17 if ((tagVal == CCNProtocolDTags.PublisherPublicKeyDigest) ||
18 (tagVal == CCNProtocolDTags.PublisherCertificateDigest) ||
19 (tagVal == CCNProtocolDTags.PublisherIssuerKeyDigest) ||
20 (tagVal == CCNProtocolDTags.PublisherIssuerCertificateDigest)) {
21 return true;
22 }
23 return false;
24};
25
26
27
28
29var PublisherID = function PublisherID() {
30
31 this.PUBLISHER_ID_DIGEST_ALGORITHM = "SHA-256";
32 this.PUBLISHER_ID_LEN = 256/8;
33
34 //TODO, implement publisherID creation and key creation
35
36 //TODO implement generatePublicKeyDigest
37 this.PublisherID =null;//= generatePublicKeyDigest(key);//ByteArray
38
39 //TODO implement generate key
40 //CryptoUtil.generateKeyID(PUBLISHER_ID_DIGEST_ALGORITHM, key);
41 this.PublisherType = null;//isIssuer ? PublisherType.ISSUER_KEY : PublisherType.KEY;//publisher Type
42
43};
44
45
46PublisherID.prototype.decode = function(decoder) {
47
48 // We have a choice here of one of 4 binary element types.
49 var nextTag = decoder.peekStartElementAsLong();
50
51 if (null == nextTag) {
52 throw new Exception("Cannot parse publisher ID.");
53 }
54
55 this.PublisherType = new PublisherType(nextTag);
56
57 if (!isTypeTagVal(nextTag)) {
58 throw new Exception("Invalid publisher ID, got unexpected type: " + nextTag);
59 }
60 this.PublisherID = decoder.readBinaryElement(nextTag);
61 if (null == this.PublisherID) {
62 throw new ContentDecodingException("Cannot parse publisher ID of type : " + nextTag + ".");
63 }
64};
65
66PublisherID.prototype.encode = function(encoder) {
67 if (!this.validate()) {
68 throw new Exception("Cannot encode " + this.getClass().getName() + ": field values missing.");
69 }
70
71 encoder.writeElement(this.getElementLabel(), this.PublisherID);
72};
73
Meki Cherkaoui8f173612012-06-06 01:05:40 -070074PublisherID.peek = function(
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070075 //XMLDecoder
76 decoder) {
77
78 //Long
79 nextTag = decoder.peekStartElementAsLong();
80
81 if (null == nextTag) {
82 // on end element
83 return false;
84 }
85 return (isTypeTagVal(nextTag));
86 };
87
88PublisherID.prototype.getElementLabel = function() {
89 return this.PublisherType.Tag;
90};
91
92PublisherID.prototype.validate = function(){
93 return ((null != id() && (null != type())));
94};
95
96
97