go.crypto/otr: expose IsEncrypted.

It's useful to expose this bit of state because, although callers can
keep track of it themselves, it's already in the Conversation so it
seems wasteful to make them do so.

R=golang-dev, ioerror
CC=golang-dev
https://golang.org/cl/6724056
This commit is contained in:
Adam Langley
2012-10-17 14:58:16 -04:00
parent 4ce1924ebb
commit c9c0e06eed
2 changed files with 21 additions and 0 deletions
+7
View File
@@ -508,6 +508,13 @@ func (c *Conversation) End() (toSend [][]byte) {
panic("unreachable")
}
// IsEncrypted returns true if a message passed to Send would be encrypted
// before transmission. This result remains valid until the next call to
// Receive or End, which may change the state of the Conversation.
func (c *Conversation) IsEncrypted() bool {
return c.state == stateEncrypted
}
var fragmentError = errors.New("otr: invalid OTR fragment")
// processFragment processes a fragmented OTR message and possibly returns a
+14
View File
@@ -139,6 +139,13 @@ func TestConversation(t *testing.T) {
var err error
alicesMessage = append(alicesMessage, []byte(QueryMessage))
if alice.IsEncrypted() {
t.Error("Alice believes that the conversation is secure before we've started")
}
if bob.IsEncrypted() {
t.Error("Bob believes that the conversation is secure before we've started")
}
for round := 0; len(alicesMessage) > 0 || len(bobsMessage) > 0; round++ {
bobsMessage = nil
for i, msg := range alicesMessage {
@@ -180,6 +187,13 @@ func TestConversation(t *testing.T) {
t.Errorf("Session identifiers don't match. Alice has %x, Bob has %x", alice.SSID[:], bob.SSID[:])
}
if !alice.IsEncrypted() {
t.Error("Alice doesn't believe that the conversation is secure")
}
if !bob.IsEncrypted() {
t.Error("Bob doesn't believe that the conversation is secure")
}
var testMessage = []byte("hello Bob")
alicesMessage, err = alice.Send(testMessage)
for i, msg := range alicesMessage {