Пример #1
0
def encrypt(ctx, key, password):
    note = get_note(ctx.data, key)

    aes_key = crypt.password_digest(password)
    ciphertext = crypt.encrypt(note.content, aes_key)
    encrypted_note = Note.create(note.title, encrypted=True)

    # TODO: Refacator this out, see container.Note
    with encrypted_note.path.open('bw') as f:
        f.write(ciphertext)
Пример #2
0
def show(ctx, key, lang):
    """Show a specific note."""
    note = get_note(ctx.data, key)
    if lang and config.COLORS:
        content = highlight_(note.content.decode(), lang)
    elif lang and config.COLORS is False:
        echo_error('Color support is not enabled!')
        exit(1)
    else:
        content = note.content.decode()

    if ctx.no_header:
        output = content
    else:
        output = note.get_header() + '\n\n' + content

    echo(output, ctx.no_pager)
Пример #3
0
def edit(ctx, key, title):
    """Edit a specific note."""
    note = get_note(ctx.data, key)
    if title:
        new_title = click.edit(note.title, editor=config.EDITOR)
        if new_title:
            new_title = new_title.strip()
        else:
            echo_hint('No changes detected')

        new_path = note.path.parent / Path(new_title)
        note.path.rename(new_path)
        note.path = new_path
        note.path.touch()  # Update mtime
    else:
        new_content = click.edit(note.content.decode(), editor=config.EDITOR,
                                 extension=config.EXTENSION)
        if new_content:
            note.content = new_content.encode()
        else:
            echo_hint('No changes detected')
Пример #4
0
def decrypt(ctx, key, password):
    note = get_note(ctx.data, key)

    aes_key = crypt.password_digest(password)
    ciphertext = crypt.encrypt(note.content, aes_key)
    print(ciphertext)