-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 45f7e20
Showing
28 changed files
with
12,041 additions
and
0 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,15 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 skythen | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,7 @@ | ||
# GobalPlatform | ||
|
||
GobalPlatform is a collection of Golang packages that provide functions for interacting with Cards/Secure Elements that implement the GlobalPlatform Card Specification. | ||
|
||
The targeted version is the GPC v2.3.1 but most parts are downward compatible. | ||
|
||
The packages are WIP and provided without warranty. |
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,32 @@ | ||
// Package aid provides functions for handling AID as specified in ISO/IEC 7816-5. | ||
package aid | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// AID is an identifier for a chip card application. | ||
type AID []byte | ||
|
||
// ParseAID parses an application identifier from bytes and returns an AID. | ||
// A valid application identifier has a length of 5-16 bytes. | ||
func ParseAID(b []byte) (*AID, error) { | ||
if len(b) < 5 || len(b) > 16 { | ||
return nil, fmt.Errorf("AID must have a length of 5-16 bytes, got: %d", len(b)) | ||
} | ||
|
||
aid := AID(b) | ||
|
||
return &aid, nil | ||
} | ||
|
||
// RID returns the Registered Identifier of an AID which consists of its first 5 bytes. | ||
func (a AID) RID() []byte { | ||
return a[:5] | ||
} | ||
|
||
// PIX returns the Proprietary Application Identifier Extension of an AID | ||
// which consists of all byte following its first five bytes. | ||
func (a AID) PIX() []byte { | ||
return a[5:] | ||
} |
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,97 @@ | ||
package aid | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"gobalplatform/internal/util" | ||
) | ||
|
||
func TestParseAID(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inputBytes []byte | ||
expected *AID | ||
expectError bool | ||
}{ | ||
{ | ||
name: "valid AID", | ||
inputBytes: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, | ||
expected: &AID{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Error: invalid length, too short", | ||
inputBytes: []byte{0x01, 0x02, 0x03, 0x04}, | ||
expected: nil, | ||
expectError: true, | ||
}, | ||
{ | ||
name: "Error: invalid length, too long", | ||
inputBytes: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}, | ||
expected: nil, | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
received, err := ParseAID(tc.inputBytes) | ||
|
||
util.EvaluateTestWithError(t, tc.expectError, err, tc.expected, received) | ||
}) | ||
} | ||
} | ||
|
||
func TestAID_RID(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
aid AID | ||
expected []byte | ||
}{ | ||
{ | ||
name: "get RID", | ||
aid: AID{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, | ||
expected: []byte{0x01, 0x02, 0x03, 0x04, 0x05}, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
received := tc.aid.RID() | ||
|
||
if !bytes.Equal(tc.expected, received) { | ||
t.Errorf("Expected: '%v', got: '%v'", tc.expected, received) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAID_PIX(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
aid AID | ||
expected []byte | ||
}{ | ||
{ | ||
name: "get PIX", | ||
aid: AID{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, | ||
expected: []byte{0x06, 0x07}, | ||
}, | ||
{ | ||
name: "empty PIX", | ||
aid: AID{0x01, 0x02, 0x03, 0x04, 0x05}, | ||
expected: nil, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
received := tc.aid.PIX() | ||
|
||
if !bytes.Equal(tc.expected, received) { | ||
t.Errorf("Expected: '%v', got: '%v'", tc.expected, received) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.