diff --git a/otr/otr.go b/otr/otr.go index e4890d5..30b39fb 100644 --- a/otr/otr.go +++ b/otr/otr.go @@ -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 diff --git a/otr/otr_test.go b/otr/otr_test.go index 1478609..1e2bbfc 100644 --- a/otr/otr_test.go +++ b/otr/otr_test.go @@ -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 {