Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gajim-plugins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evert Mouw
gajim-plugins
Commits
2be20182
Commit
2be20182
authored
9 years ago
by
Bahtiar Gadimov
Browse files
Options
Downloads
Patches
Plain Diff
Add EncryptionState
parent
ee79762e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
omemo/store/encryption.py
+58
-0
58 additions, 0 deletions
omemo/store/encryption.py
omemo/test_encryption_store.py
+31
-0
31 additions, 0 deletions
omemo/test_encryption_store.py
with
89 additions
and
0 deletions
omemo/store/encryption.py
0 → 100644
+
58
−
0
View file @
2be20182
# -*- coding: utf-8 -*-
#
# Copyright 2015 Bahtiar `kalkin-` Gadimov <bahtiar@gadimov.de>
# Copyright 2015 Daniel Gultsch <daniel@cgultsch.de>
#
# This file is part of Gajim-OMEMO plugin.
#
# The Gajim-OMEMO plugin is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Gajim-OMEMO is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# the Gajim-OMEMO plugin. If not, see <http://www.gnu.org/licenses/>.
#
class
EncryptionState
():
"""
Used to store if OMEMO is enabled or not between gajim restarts
"""
def
__init__
(
self
,
dbConn
):
"""
:type dbConn: Connection
"""
self
.
dbConn
=
dbConn
dbConn
.
execute
(
"""
CREATE TABLE IF NOT EXISTS encryption_state (
jid TEXT PRIMARY KEY,
encryption INTEGER,
timestamp NUMBER DEFAULT CURRENT_TIMESTAMP
) WITHOUT ROWID;
"""
)
def
activate
(
self
,
jid
):
q
=
"""
INSERT OR REPLACE INTO encryption_state (jid, encryption)
VALUES (?, 1)
"""
c
=
self
.
dbConn
.
cursor
()
c
.
execute
(
q
,
(
jid
,))
self
.
dbConn
.
commit
()
def
deactivate
(
self
,
jid
):
q
=
"""
INSERT OR REPLACE INTO encryption_state (jid, encryption)
VALUES (?, 0)
"""
c
=
self
.
dbConn
.
cursor
()
c
.
execute
(
q
,
(
jid
,))
self
.
dbConn
.
commit
()
def
is_active
(
self
,
jid
):
q
=
'
SELECT encryption FROM encryption_state where jid = ?;
'
c
=
self
.
dbConn
.
cursor
()
c
.
execute
(
q
,
(
jid
,))
result
=
c
.
fetchone
()
if
result
is
None
:
return
False
return
result
[
0
]
==
1
This diff is collapsed.
Click to expand it.
omemo/test_encryption_store.py
0 → 100644
+
31
−
0
View file @
2be20182
import
unittest
from
store.encryption
import
EncryptionState
import
os
import
sqlite3
class
TestEncryptionStateStore
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
conn
=
sqlite3
.
connect
(
'
test-db
'
,
check_same_thread
=
False
)
self
.
e
=
EncryptionState
(
self
.
conn
)
def
test_create
(
self
):
self
.
assertEquals
(
self
.
e
.
is_active
(
'
romeo@example.com
'
),
False
)
def
test_enable_encryption
(
self
):
self
.
e
.
activate
(
'
romeo@example.com
'
)
self
.
assertEquals
(
self
.
e
.
is_active
(
'
romeo@example.com
'
),
True
)
def
test_disable_encryption
(
self
):
self
.
e
.
activate
(
'
romeo@example.com
'
)
self
.
assertEquals
(
self
.
e
.
is_active
(
'
romeo@example.com
'
),
True
)
self
.
e
.
deactivate
(
'
romeo@example.com
'
)
self
.
assertEquals
(
self
.
e
.
is_active
(
'
romeo@example.com
'
),
False
)
def
tearDown
(
self
):
os
.
remove
(
'
test-db
'
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment