-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jimsch/master
Changes to match JAVA API and framework
- Loading branch information
Showing
32 changed files
with
560 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
using PeterO.Cbor; | ||
|
||
namespace Com.AugustCellars.COSE | ||
{ | ||
public class Attributes | ||
{ | ||
protected CBORObject objProtected = CBORObject.NewMap(); | ||
protected CBORObject objUnprotected = CBORObject.NewMap(); | ||
protected CBORObject objDontSend = CBORObject.NewMap(); | ||
protected byte[] externalData = new byte[0]; | ||
protected byte[] rgbProtected; | ||
|
||
static public int PROTECTED = 1; | ||
static public int UNPROTECTED = 2; | ||
static public int DO_NOT_SEND = 4; | ||
|
||
public void AddAttribute(string name, string value, int bucket) | ||
{ | ||
AddAttribute(CBORObject.FromObject(name), CBORObject.FromObject(value), bucket); | ||
} | ||
|
||
public void AddAttribute(string name, CBORObject value, int bucket) | ||
{ | ||
AddAttribute(CBORObject.FromObject(name), value, bucket); | ||
} | ||
|
||
public void AddAttribute(CBORObject label, CBORObject value, int bucket) | ||
{ | ||
RemoveAttribute(label); | ||
switch (bucket) { | ||
case 1: | ||
objProtected.Add(label, value); | ||
break; | ||
|
||
case 2: | ||
objUnprotected.Add(label, value); | ||
break; | ||
|
||
case 4: | ||
objDontSend.Add(label, value); | ||
break; | ||
|
||
default: | ||
throw new CoseException("Invalid bucket provided to place attribute in"); | ||
} | ||
} | ||
|
||
[System.Obsolete("Use AddAttribute(string, string, Attributes.Protected")] | ||
public void AddAttribute(string name, string value, bool fProtected) | ||
{ | ||
AddAttribute(name, value, fProtected ? PROTECTED : UNPROTECTED); | ||
} | ||
|
||
[System.Obsolete("Use AddAttribute(string, CBORObject, Attributes.Protected")] | ||
public void AddAttribute(string name, CBORObject value, bool fProtected) | ||
{ | ||
AddAttribute(name, value, fProtected ? PROTECTED : UNPROTECTED); | ||
} | ||
|
||
[System.Obsolete("Use AddAttribute(key, value, Attributes.Protected)")] | ||
public void AddAttribute(CBORObject key, CBORObject value, bool fProtected) | ||
{ | ||
if (fProtected) AddProtected(key, value); | ||
else AddUnprotected(key, value); | ||
} | ||
|
||
[System.Obsolete("Use AddAttribue(label, value, Attributes.Protected)")] | ||
public void AddProtected(string label, string value) | ||
{ | ||
AddProtected(label, CBORObject.FromObject(value)); | ||
} | ||
|
||
[System.Obsolete("Use AddAttribue(label, value, Attributes.Protected)")] | ||
public void AddProtected(string label, CBORObject value) | ||
{ | ||
AddProtected(CBORObject.FromObject(label), value); | ||
} | ||
|
||
[System.Obsolete("Use AddAttribue(label, value, Attributes.Unprotected)")] | ||
public void AddUnprotected(string label, string value) | ||
{ | ||
AddUnprotected(label, CBORObject.FromObject(label)); | ||
} | ||
|
||
[System.Obsolete("Use AddAttribue(label, value, Attributes.Unprotected)")] | ||
public void AddUnprotected(string label, CBORObject value) | ||
{ | ||
AddUnprotected(CBORObject.FromObject(label), value); | ||
} | ||
|
||
[System.Obsolete("Use AddAttribue(label, value, Attributes.Protected)")] | ||
public void AddProtected(CBORObject label, CBORObject value) | ||
{ | ||
RemoveAttribute(label); | ||
objProtected.Add(label, value); | ||
} | ||
|
||
[System.Obsolete("Use AddAttribue(label, value, Attributes.Unprotected)")] | ||
public void AddUnprotected(CBORObject label, CBORObject value) | ||
{ | ||
RemoveAttribute(label); | ||
objUnprotected.Add(label, value); | ||
} | ||
|
||
[System.Obsolete("Use AddAttribue(label, value, Attributes.DoNotSend)")] | ||
public void AddDontSend(CBORObject label, CBORObject value) | ||
{ | ||
RemoveAttribute(label); | ||
objDontSend.Add(label, value); | ||
} | ||
|
||
public CBORObject FindAttribute(CBORObject label) | ||
{ | ||
if (objProtected.ContainsKey(label)) return objProtected[label]; | ||
if (objUnprotected.ContainsKey(label)) return objUnprotected[label]; | ||
if (objDontSend.ContainsKey(label)) return objDontSend[label]; | ||
return null; | ||
} | ||
|
||
public CBORObject FindAttribute(int label) | ||
{ | ||
return FindAttribute(CBORObject.FromObject(label)); | ||
} | ||
|
||
public CBORObject FindAttribute(string label) | ||
{ | ||
return FindAttribute(CBORObject.FromObject(label)); | ||
} | ||
|
||
private void RemoveAttribute(CBORObject label) | ||
{ | ||
if (objProtected.ContainsKey(label)) objProtected.Remove(label); | ||
if (objUnprotected.ContainsKey(label)) objUnprotected.Remove(label); | ||
if (objDontSend.ContainsKey(label)) objDontSend.Remove(label); | ||
} | ||
|
||
public void SetExternalData(byte[] newData) | ||
{ | ||
externalData = newData; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.