Skip to content

Commit c9c0e06

Browse files
committed
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
1 parent 4ce1924 commit c9c0e06

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

otr/otr.go

+7
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,13 @@ func (c *Conversation) End() (toSend [][]byte) {
508508
panic("unreachable")
509509
}
510510

511+
// IsEncrypted returns true if a message passed to Send would be encrypted
512+
// before transmission. This result remains valid until the next call to
513+
// Receive or End, which may change the state of the Conversation.
514+
func (c *Conversation) IsEncrypted() bool {
515+
return c.state == stateEncrypted
516+
}
517+
511518
var fragmentError = errors.New("otr: invalid OTR fragment")
512519

513520
// processFragment processes a fragmented OTR message and possibly returns a

otr/otr_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ func TestConversation(t *testing.T) {
139139
var err error
140140
alicesMessage = append(alicesMessage, []byte(QueryMessage))
141141

142+
if alice.IsEncrypted() {
143+
t.Error("Alice believes that the conversation is secure before we've started")
144+
}
145+
if bob.IsEncrypted() {
146+
t.Error("Bob believes that the conversation is secure before we've started")
147+
}
148+
142149
for round := 0; len(alicesMessage) > 0 || len(bobsMessage) > 0; round++ {
143150
bobsMessage = nil
144151
for i, msg := range alicesMessage {
@@ -180,6 +187,13 @@ func TestConversation(t *testing.T) {
180187
t.Errorf("Session identifiers don't match. Alice has %x, Bob has %x", alice.SSID[:], bob.SSID[:])
181188
}
182189

190+
if !alice.IsEncrypted() {
191+
t.Error("Alice doesn't believe that the conversation is secure")
192+
}
193+
if !bob.IsEncrypted() {
194+
t.Error("Bob doesn't believe that the conversation is secure")
195+
}
196+
183197
var testMessage = []byte("hello Bob")
184198
alicesMessage, err = alice.Send(testMessage)
185199
for i, msg := range alicesMessage {

0 commit comments

Comments
 (0)