Major update: refactored the API of all classes to make attributes start with a lower case letter and rename encode=>to_ccnb() and decode()=>from_ccnb.
(according to the API notes: http://sea.remap.ucla.edu:8080/attachments/download/23/lwndn_api-notes_21020830.txt )
diff --git a/js/SignedInfo.js b/js/SignedInfo.js
index b2ff0b2..909545a 100644
--- a/js/SignedInfo.js
+++ b/js/SignedInfo.js
@@ -14,19 +14,19 @@
//TODO, Check types
- this.Publisher = _publisher; //PublisherPublicKeyDigest
- this.Timestamp=_timestamp; // CCN Time
- this.Type=_type; // ContentType
- this.Locator =_locator;//KeyLocator
- this.FreshnessSeconds =_freshnessSeconds; // Integer
- this.FinalBlockID=_finalBlockID; //byte array
+ this.publisher = _publisher; //publisherPublicKeyDigest
+ this.timestamp=_timestamp; // CCN Time
+ this.type=_type; // ContentType
+ this.locator =_locator;//KeyLocator
+ this.freshnessSeconds =_freshnessSeconds; // Integer
+ this.finalBlockID=_finalBlockID; //byte array
};
SignedInfo.prototype.setFields = function(){
//BASE64 -> RAW STRING
- //this.Locator = new KeyLocator( DataUtils.toNumbersFromString(stringCertificate) ,KeyLocatorType.CERTIFICATE );
+ //this.locator = new KeyLocator( DataUtils.toNumbersFromString(stringCertificate) ,KeyLocatorType.CERTIFICATE );
var publicKeyHex = globalKeyManager.publicKey;
@@ -49,48 +49,48 @@
var publisherKeyDigest = hex_sha256_from_bytes(publicKeyBytes);
- this.Publisher = new PublisherPublicKeyDigest( DataUtils.toNumbers( publisherKeyDigest ) );
+ this.publisher = new PublisherPublicKeyDigest( DataUtils.toNumbers( publisherKeyDigest ) );
- //this.Publisher = new PublisherPublicKeyDigest(publisherkey);
+ //this.publisher = new PublisherPublicKeyDigest(publisherkey);
var d = new Date();
var time = d.getTime();
- this.Timestamp = new CCNTime( time );
+ this.timestamp = new CCNTime( time );
if(LOG>4)console.log('TIME msec is');
- if(LOG>4)console.log(this.Timestamp.msec);
+ if(LOG>4)console.log(this.timestamp.msec);
//DATA
- this.Type = 0;//0x0C04C0;//ContentTypeValue[ContentType.DATA];
+ this.type = 0;//0x0C04C0;//ContentTypeValue[ContentType.DATA];
//if(LOG>4)console.log('toNumbersFromString(stringCertificate) '+DataUtils.toNumbersFromString(stringCertificate));
console.log('PUBLIC KEY TO WRITE TO CONTENT OBJECT IS ');
console.log(publicKeyBytes);
- this.Locator = new KeyLocator( publicKeyBytes ,KeyLocatorType.KEY );
+ this.locator = new KeyLocator( publicKeyBytes ,KeyLocatorType.KEY );
- //this.Locator = new KeyLocator( DataUtils.toNumbersFromString(stringCertificate) ,KeyLocatorType.CERTIFICATE );
+ //this.locator = new KeyLocator( DataUtils.toNumbersFromString(stringCertificate) ,KeyLocatorType.CERTIFICATE );
};
-SignedInfo.prototype.decode = function( decoder){
+SignedInfo.prototype.from_ccnb = function( decoder){
decoder.readStartElement( this.getElementLabel() );
if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) {
if(LOG>3) console.log('DECODING PUBLISHER KEY');
- this.Publisher = new PublisherPublicKeyDigest();
- this.Publisher.decode(decoder);
+ this.publisher = new PublisherPublicKeyDigest();
+ this.publisher.from_ccnb(decoder);
}
if (decoder.peekStartElement(CCNProtocolDTags.Timestamp)) {
- this.Timestamp = decoder.readDateTime(CCNProtocolDTags.Timestamp);
- if(LOG>4)console.log('TIMESTAMP FOUND IS '+this.Timestamp);
+ this.timestamp = decoder.readDateTime(CCNProtocolDTags.Timestamp);
+ if(LOG>4)console.log('TIMESTAMP FOUND IS '+this.timestamp);
}
@@ -98,72 +98,72 @@
binType = decoder.readBinaryElement(CCNProtocolDTags.Type);//byte []
- //TODO Implement Type of Key Reading
+ //TODO Implement type of Key Reading
if(LOG>4)console.log('Binary Type of of Signed Info is '+binType);
- this.Type = binType;
+ this.type = binType;
- //TODO Implement Type of Key Reading
+ //TODO Implement type of Key Reading
- if (null == this.Type) {
+ if (null == this.type) {
throw new Exception("Cannot parse signedInfo type: bytes.");
}
} else {
- this.Type = ContentType.DATA; // default
+ this.type = ContentType.DATA; // default
}
if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) {
- this.FreshnessSeconds = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds);
- if(LOG>4) console.log('FRESHNESS IN SECONDS IS '+ this.FreshnessSeconds);
+ this.freshnessSeconds = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds);
+ if(LOG>4) console.log('FRESHNESS IN SECONDS IS '+ this.freshnessSeconds);
}
if (decoder.peekStartElement(CCNProtocolDTags.FinalBlockID)) {
- this.FinalBlockID = decoder.readBinaryElement(CCNProtocolDTags.FinalBlockID);
+ this.finalBlockID = decoder.readBinaryElement(CCNProtocolDTags.FinalBlockID);
}
if (decoder.peekStartElement(CCNProtocolDTags.KeyLocator)) {
- this.Locator = new KeyLocator();
- this.Locator.decode(decoder);
+ this.locator = new KeyLocator();
+ this.locator.from_ccnb(decoder);
}
decoder.readEndElement();
};
-SignedInfo.prototype.encode = function( encoder) {
+SignedInfo.prototype.to_ccnb = function( encoder) {
if (!this.validate()) {
throw new Exception("Cannot encode : field values missing.");
}
encoder.writeStartElement(this.getElementLabel());
- if (null!=this.Publisher) {
- if(LOG>3) console.log('ENCODING PUBLISHER KEY' + this.Publisher.PublisherPublicKeyDigest);
+ if (null!=this.publisher) {
+ if(LOG>3) console.log('ENCODING PUBLISHER KEY' + this.publisher.publisherPublicKeyDigest);
- this.Publisher.encode(encoder);
+ this.publisher.to_ccnb(encoder);
}
- if (null!=this.Timestamp) {
- encoder.writeDateTime(CCNProtocolDTags.Timestamp, this.Timestamp );
+ if (null!=this.timestamp) {
+ encoder.writeDateTime(CCNProtocolDTags.Timestamp, this.timestamp );
}
- if (null!=this.Type && this.Type !=0) {
+ if (null!=this.type && this.type !=0) {
- encoder.writeElement(CCNProtocolDTags.Type, this.Type);
+ encoder.writeElement(CCNProtocolDTags.type, this.type);
}
- if (null!=this.FreshnessSeconds) {
- encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, this.FreshnessSeconds);
+ if (null!=this.freshnessSeconds) {
+ encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, this.freshnessSeconds);
}
- if (null!=this.FinalBlockID) {
- encoder.writeElement(CCNProtocolDTags.FinalBlockID, this.FinalBlockID);
+ if (null!=this.finalBlockID) {
+ encoder.writeElement(CCNProtocolDTags.FinalBlockID, this.finalBlockID);
}
- if (null!=this.Locator) {
- this.Locator.encode(encoder);
+ if (null!=this.locator) {
+ this.locator.to_ccnb(encoder);
}
encoder.writeEndElement();
@@ -185,7 +185,7 @@
SignedInfo.prototype.validate = function() {
// We don't do partial matches any more, even though encoder/decoder
// is still pretty generous.
- if (null ==this.Publisher || null==this.Timestamp ||null== this.Locator)
+ if (null ==this.publisher || null==this.timestamp ||null== this.locator)
return false;
return true;
};