Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PlaintextSize method to Enclaves #120

Merged
merged 5 commits into from Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/enclave.go
Expand Up @@ -113,3 +113,10 @@ func Open(e *Enclave) (*Buffer, error) {
// Return the contents of the Enclave inside a Buffer.
return b, nil
}

/*
EnclaveSize returns the number of bytes of plaintext data stored inside an Enclave.
*/
func EnclaveSize(e *Enclave) int {
return len(e.ciphertext) - Overhead
}
6 changes: 6 additions & 0 deletions core/enclave_test.go
Expand Up @@ -135,3 +135,9 @@ func TestOpen(t *testing.T) {
t.Error("expected nil buffer in error case")
}
}

func TestEnclaveSize(t *testing.T) {
if EnclaveSize(&Enclave{make([]byte, 1234)}) != 1234-Overhead {
t.Error("invalid enclave size")
}
}
7 changes: 7 additions & 0 deletions enclave.go
Expand Up @@ -50,3 +50,10 @@ func (e *Enclave) Open() (*LockedBuffer, error) {
b.Freeze()
return newBuffer(b), nil
}

/*
Size returns the number of bytes of data stored within an Enclave.
*/
func (e *Enclave) Size() int {
return core.EnclaveSize(e.Enclave)
}
3 changes: 3 additions & 0 deletions enclave_test.go
Expand Up @@ -60,6 +60,9 @@ func TestOpen(t *testing.T) {
if b == nil {
t.Error("buffer should not be nil")
}
if e.Size() != b.Size() {
t.Error("sizes don't match")
}
if !bytes.Equal(b.Bytes(), []byte("yellow submarine")) {
t.Error("data does not match")
}
Expand Down