Skip to content

Commit

Permalink
Merge pull request #37 from jimsch/master
Browse files Browse the repository at this point in the history
Restore public on the attribute class
  • Loading branch information
jimsch authored Nov 30, 2016
2 parents 4e5e7b6 + f44b1f0 commit b306303
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/COSE/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author jimsch
*/

class Attribute {
public class Attribute {
/**
* Internal map of protected attributes
*/
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/COSE/OneKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,57 @@ static private OneKey generateECDSAKey(String curveName, CBORObject curve) {

return key;
}

/**
* Create a OneKey object with only the public fields. Filters out the
* private key fields but leaves all positive number labels and text labels
* along with negative number labels that are public fields.
*
* @return public version of the key
*/
public OneKey PublicKey()
{
OneKey newKey = new OneKey();
CBORObject val = this.get(KeyKeys.KeyType);
if (val.equals(KeyKeys.KeyType_Octet)) {
return null;
}
else if (val.equals(KeyKeys.KeyType_EC2)) {
newKey.add(KeyKeys.EC2_Curve, get(KeyKeys.EC2_Curve));
newKey.add(KeyKeys.EC2_X, get(KeyKeys.EC2_X));
newKey.add(KeyKeys.EC2_Y, get(KeyKeys.EC2_Y));
}
/*
else if (val.equals(KeyKeys.KeyType_OKP)) {
newKey.add(KeyKeys.OKP_Curve, get(KeyKeys.OKP_Curve));
newKey.add(KeyKeys.OKP_X, get(KeyKeys.OKP_X));
}
*/
else {
return null;
}

for (CBORObject obj : keyMap.getKeys()) {
val = keyMap.get(obj);
if (obj.getType() == CBORType.Number) {
if (obj.AsInt32() > 0) {
newKey.add(obj, val);
}
}
else if (obj.getType() == CBORType.TextString) {
newKey.add(obj, val);
}
}
return newKey;
}

/**
* Encode to a byte string
*
* @return encoded object as bytes.
*/
public byte[] EncodeToBytes()
{
return keyMap.EncodeToBytes();
}
}

0 comments on commit b306303

Please sign in to comment.