小编Ale*_*lds的帖子

为什么HMAC SHA-1会使用相同的输入返回不同的摘要?

我正在尝试为Amazon S3 Web服务构建一个可用的加密签名,使用Objective C编写连接库.

我已经遇到了使用ObjC代码的HMAC SHA-1摘要问题,因此我将其放在一边,查看现有的,正在运行的Perl代码,以尝试解决摘要创建问题.

我正在测试包的s3ls命令中的HMAC SHA-1摘要输出Net::Amazon::S3,并将其与_encode我提取并放入其自己的perl脚本的子例程进行比较:

#!/usr/bin/perl -w                                                                                                                                                                                    

use MIME::Base64 qw(encode_base64);
use Digest::HMAC_SHA1;
use String::Escape qw( printable unprintable );

sub _ascii_to_hex {
    (my $str = shift) =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg;
    return $str;
}

sub _encode {
    my ( $aws_secret_access_key, $str ) = @_;
    print "secret key hex: "._ascii_to_hex($aws_secret_access_key)."\n";
    my $hmac = Digest::HMAC_SHA1->new($aws_secret_access_key);
    $hmac->add($str);
    my $digest = $hmac->digest;
    print "cleartext hex: "._ascii_to_hex($str)."\n";
    print "digest hex: "._ascii_to_hex($digest)."\n";
    my $b64 = encode_base64( $digest, '' ); …
Run Code Online (Sandbox Code Playgroud)

encryption perl sha1 digest hmac

5
推荐指数
1
解决办法
5271
查看次数

Java相当于Cocoa NSNotification?

我正在使用SWT小部件编写Java应用程序.我想在某个事件发生时更新某些小部件的状态(例如,更新数据模型的状态).

Java中是否存在类似于Cocoa的NSNotificationCenter的东西,我可以在其中注册一个对象来监听通知事件并对它们做出响应,以及让其他对象"触发"通知?

java events cocoa notifications objective-c

5
推荐指数
1
解决办法
3250
查看次数

旋转iPhone时重置自定义UITableViewCell高度

我正在重载委托方法-tableView:heightForRowAtIndexPath:并使用-sizeWithFont:constrainedToSize:以编程方式设置单元格的高度,基于该单元格中的文本:

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  switch (indexPath.section) {
    case(kAboutViewOverviewSection): {
      switch (indexPath.row) {
        case(kAboutViewOverviewSectionRow): {
          NSString *text = NSLocalizedString(@"kAboutViewOverviewSectionFieldText", @"");
          CGSize s = [text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(280, 500)];
          return s.height + 13;
        }
        default: {
          break;
        }
      }
      break;
    }
    default: {
      break;
    }
  }
  return 44.0;
}
Run Code Online (Sandbox Code Playgroud)

这在第一次绘制表时有效.但是,当我更改设备的方向时,从纵向到横向,单元格高度不会改变.

我尝试-shouldAutorotateToInterfaceOrientation:在表视图控制器中覆盖该方法:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  [self.tableView reloadData];
  return YES;
}
Run Code Online (Sandbox Code Playgroud)

这应该重新加载表数据并且(可能)重绘表格单元格视图.但这没有任何影响.

当设备旋转时,有没有办法强制单元格以新的高度重绘?

编辑:我尝试了以下,没有效果:

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  [self.tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)

以下是纵向应用程序的外观: …

iphone uitableview

5
推荐指数
1
解决办法
1万
查看次数

我可以在应用程序运行时以编程方式翻转Info.plist值吗?

我有兴趣在我的应用程序中使用SBUsesNetworkUIRequiresPersistentWiFi键; 但是,我想只在使用某组视图控制器时启用它们.有没有办法在应用程序运行时以编程方式翻转这些键值?

iphone info.plist reachability

5
推荐指数
1
解决办法
4023
查看次数

How to manage two or more consumers via pthreads?

I have a generic problem I am looking to solve, where chunks of binary data sent from a standard input or regular file stream to an application, which in turn converts that binary data into text. Using threads, I want to process the text before piping it over to the next application, which modifies that text even further, and so on.

As a simple test case, I want to extract compressed data via gunzip. Specifically, I am looking at …

c io multithreading buffer pthreads

5
推荐指数
1
解决办法
606
查看次数

避免千言万语的最佳方法?

我基本上有这个问题:现在,我们有一个系统,它获取一个字符串作为输入,它基本上说ACTION:.

对于每个动作,都有一个自动生成的函数(Rational Rose GRRR),例如

bouncer_comm.chatMessage("data goes here").sendAt(msg->sapIndex0());
bouncer_comm.askforname().sendAt(msg->sapindex0());
Run Code Online (Sandbox Code Playgroud)

bouncer_comm返回一个RTOutSignal,我无法手动创建它们,因为玫瑰使用了奇怪的结构.

现在,我唯一的选择是创建一百个左右的if语句,我这样做:

if(action == "CHAT")  bouncer_comm.chatMessage("data goes here").sendAt(msg->sapIndex0());
Run Code Online (Sandbox Code Playgroud)

这真是令人烦恼.

什么是避免这种情况的最佳方法?我看过/试过无数的东西,这是理性玫瑰(前2k)的旧版本,是的.

如果有人有任何想法会很惊人.

c++ boost rational-rose

4
推荐指数
2
解决办法
1833
查看次数

我是否需要担心Valgrind报告我的申请范围之外的错误?

在运行Valgrind的memcheck工具时,我经常会得到数十万(或更多,因为Valgrind切断100K)的小的无效读取语句,例如:

==32027== Invalid read of size 1
==32027==    at 0x3AB426E26A: _IO_default_xsputn (in /lib64/libc-2.5.so)
==32027==    by 0x3AB426CF70: _IO_file_xsputn@@GLIBC_2.2.5 (in /lib64/libc-2.5.so)
==32027==    by 0x3AB42621FA: fwrite (in /lib64/libc-2.5.so)
==32027==    by 0x4018CA: STARCH_gzip_deflate (in /home/areynolds/trunk/utility/applications/bed/starch/bin/starch)
==32027==    by 0x401F48: compressFileWithGzip (in /home/areynolds/trunk/utility/applications/bed/starch/bin/starch)
==32027==    by 0x4028B5: transformInput (in /home/areynolds/trunk/utility/applications/bed/starch/bin/starch)
==32027==    by 0x402F12: main (in /home/areynolds/trunk/utility/applications/bed/starch/bin/starch)
==32027==  Address 0x7febb9b3c is on thread 1's stack
Run Code Online (Sandbox Code Playgroud)

这些语句指的是对我的应用程序之外的函数(" starch")的调用,它们似乎是其中的一部分libc.这是我需要关注的吗?

编辑

如果我修改fwrite调用以删除一个字节,那么我的gzip流会被破坏.这是原始代码:

int STARCH_gzip_deflate(FILE *source, FILE *dest, int level) {                                                                                                                                                                                                              

    int ret, flush;                                                                                                                                                                                                                                                         
    unsigned …
Run Code Online (Sandbox Code Playgroud)

c linux valgrind libc

4
推荐指数
1
解决办法
1229
查看次数

为什么运行它不会发出分段错误?

可能重复:
无效的读/写有时会产生分段错误,有时则不会

我有以下代码:

#include <stdlib.h>
#include <stdio.h>

int main() {
    int *ptr = NULL;
    ptr = malloc(sizeof(char));
    if (ptr) {
        *ptr = 10;
        printf("sizeof(int): %zu\nsizeof(char): %zu\n", sizeof(int), sizeof(char));
        printf("deref of ptr: %d\n", *ptr);
        free(ptr);
        return EXIT_SUCCESS;
    }
    else
        return EXIT_FAILURE;
}
Run Code Online (Sandbox Code Playgroud)

当我编译并运行它时,我得到以下输出:

$ gcc test.c
$ ./a.out 
sizeof(int): 4
sizeof(char): 1
deref of ptr: 10
Run Code Online (Sandbox Code Playgroud)

该值sizeof(char)小于sizeof(int).我的malloc电话只留出足够的空间char.然而,我的程序能够分配一个整数值而ptr不会崩溃.为什么这样做?

c memory malloc gcc

4
推荐指数
2
解决办法
206
查看次数

有没有fseek/ftell可以提供错误文件大小的情况?

在C或C++中,以下内容可用于返回文件大小:

const unsigned long long at_beg = (unsigned long long) ftell(filePtr);
fseek(filePtr, 0, SEEK_END);
const unsigned long long at_end = (unsigned long long) ftell(filePtr);
const unsigned long long length_in_bytes = at_end - at_beg;
fprintf(stdout, "file size: %llu\n", length_in_bytes);
Run Code Online (Sandbox Code Playgroud)

是否有基于填充或特定情况的其他信息,可以从此代码返回错误文件大小的开发环境,编译器或操作系统?在1999年左右,C或C++规范是否有变化,这会导致此代码在某些情况下不再起作用?

对于这个问题,请假设我通过使用标志进行编译来添加大文件支持-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1.谢谢.

c c++ porting fseek ftell

4
推荐指数
1
解决办法
4311
查看次数

如何在perl模式下禁用字符组合?

当我在perl在emacs模式(最近升级到GNU Emacs的23.3.1) ::,->以及=>(也许还有其他符号的组合)减少到?,??符号.这对我复制和粘贴文本的能力造成了严重破坏,并导致可读性错误.有没有办法禁用这个"功能"?

unicode emacs perl

4
推荐指数
1
解决办法
391
查看次数