# Path: celestia/utility/gluid.py
# class GluidError(Exception):
#     pass
# 
# def retrieve_gluid(db_path):
#     try:
#         db = sqlite3.connect(db_path)
#         cur = db.execute('SELECT value FROM glshare WHERE key = ?',
#                          ('ANMP.GloftPOHM_GAIA_ENC_KEY_GLUID',))
#         value, = cur.fetchone()
#         res = json.loads(value)
#         gluid = res['data']
#     except:
#         raise GluidError('Unable to retrieve GLUID from file')
#     return gluid


import binascii
from celestia.utility.gluid import GluidError, retrieve_gluid
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# File: savedata.py
# by Arzaroth Lekva
# lekva@arzaroth.com
#


class SaveData(object):
    def __init__(self,
                 savefile, gluid, dbfile,
                 usedb, legacy):
        self.savefile = savefile
        self._gluid = gluid if gluid else b''
        self.dbfile = dbfile
        self.usedb = usedb
        self.legacy = legacy

    @property
    def gluid(self):
        if not self.legacy:
            gluid = retrieve_gluid(self.dbfile) if self.usedb else self._gluid
            try:
                gluid = binascii.a2b_base64(gluid)
            except binascii.Error:

# Path: celestia/utility/gluid.py
# class GluidError(Exception):
#     pass
# 
# def retrieve_gluid(db_path):
#     try:
#         db = sqlite3.connect(db_path)
#         cur = db.execute('SELECT value FROM glshare WHERE key = ?',
#                          ('ANMP.GloftPOHM_GAIA_ENC_KEY_GLUID',))
#         value, = cur.fetchone()
#         res = json.loads(value)
#         gluid = res['data']
#     except:
#         raise GluidError('Unable to retrieve GLUID from file')
#     return gluid


# Path: celestia/save/savedata.py
import binascii
from celestia.utility.gluid import GluidError, retrieve_gluid

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# File: savedata.py
# by Arzaroth Lekva
# lekva@arzaroth.com
#


class SaveData(object):
    def __init__(self,
                 savefile, gluid, dbfile,
                 usedb, legacy):
        self.savefile = savefile
        self._gluid = gluid if gluid else b''
        self.dbfile = dbfile
        self.usedb = usedb
        self.legacy = legacy

    @property
    def gluid(self):
        if not self.legacy:
            gluid = retrieve_gluid(self.dbfile) if self.usedb else self._gluid
            try:
                gluid = binascii.a2b_base64(gluid)
            except binascii.Error:

                raise GluidError("Bad encryption key")