Skip to content

Commit

Permalink
Merge pull request #4 from jimsch/master
Browse files Browse the repository at this point in the history
Changes to match JAVA API and framework
  • Loading branch information
jimsch authored Dec 15, 2016
2 parents e4b85bd + e56600c commit e90a0bc
Show file tree
Hide file tree
Showing 32 changed files with 560 additions and 528 deletions.
147 changes: 147 additions & 0 deletions COSE/Attributes.cs
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;
}
}
}
1 change: 1 addition & 0 deletions COSE/COSE.Net40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Attributes.cs" />
<Compile Include="ChaCha20Poly1305.cs" />
<Compile Include="EncryptMessage.cs" />
<Compile Include="Key.cs" />
Expand Down
1 change: 1 addition & 0 deletions COSE/COSE.Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Attributes.cs" />
<Compile Include="ChaCha20Poly1305.cs" />
<Compile Include="EncryptMessage.cs" />
<Compile Include="Key.cs" />
Expand Down
14 changes: 9 additions & 5 deletions COSE/COSE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>COSE</RootNamespace>
<AssemblyName>COSE</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -31,15 +32,15 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\examples\packages\BouncyCastle.1.8.1\lib\BouncyCastle.Crypto.dll</HintPath>
<HintPath>packages\BouncyCastle.1.8.1\lib\BouncyCastle.Crypto.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="CBOR, Version=2.4.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\examples\packages\PeterO.Cbor.2.4.2\lib\portable-net45+dnxcore50+netcore45+win+wpa81+wp80\CBOR.dll</HintPath>
<HintPath>packages\PeterO.Cbor.2.4.2\lib\portable-net40+sl50+win+wpa81+wp80\CBOR.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Numbers, Version=0.2.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\examples\packages\PeterO.Numbers.0.2.2\lib\portable-net45+dnxcore50+netcore45+win+wpa81+wp80\Numbers.dll</HintPath>
<HintPath>packages\PeterO.Numbers.0.2.2\lib\portable-net40+sl50+win+wpa81+wp80\Numbers.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -51,6 +52,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Attributes.cs" />
<Compile Include="ChaCha20Poly1305.cs" />
<Compile Include="EncryptMessage.cs" />
<Compile Include="Key.cs" />
Expand All @@ -66,7 +68,9 @@
<WCFMetadata Include="Service References\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 1 addition & 1 deletion COSE/COSE.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>Com.AugustCellars.COSE</id>
<version>0.0.0.2</version>
<version>0.0.0.3</version>
<authors>Jim Schaad</authors>
<owners>jimsch</owners>
<licenseUrl>https://github.com/cose-wg/COSE-csharp/license.md</licenseUrl>
Expand Down
34 changes: 0 additions & 34 deletions COSE/COSE.sln

This file was deleted.

Loading

0 comments on commit e90a0bc

Please sign in to comment.